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

前端 未结 10 620
孤城傲影
孤城傲影 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:26

    txtUserName.Clear();
    

    This code clears the textbox. It will set the Textbox value to ""

    txtUserName.Text = string.Empty;
    

    Doesn't create object. This executes faster than txtUserName.Text = "";

    txtUserName.Text = "";
    

    Creates object and affects the performance.

提交回复
热议问题