What is the difference between these three ways to clear a Textbox?

前端 未结 10 543
孤城傲影
孤城傲影 2021-02-01 17:11

I am bit confused between the below three ways to clear the contents of a textbox. I am working with WPF and found All are working, but I am unable to find the difference.

10条回答
  •  梦谈多话
    2021-02-01 17:31

    The string.Empty field is an empty string literal. It is slightly different from an empty string literal constant " ". There is a subtle difference—but one that could be significant in some scenarios. It changes the meaning of a program

    We use string.Empty and "" in a C# program. The string.Empty field is initialized to "" at runtime by the .NET Framework.

    You cannot use string.Empty as a switch case, because it cannot be determined at compile-time by the C# compiler.

    Which explain the differences of string.empty and ""

    The Clear() method does more than just remove the text from the TextBox. It deletes all content and resets the text selection

提交回复
热议问题