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.
Let's go through the commands one by one.
txtUserName.Clear();
The Clear()
command assigns the texbox an empty string just like the next example.
Source (best explination is given by syned on this point)
txtUserName.Text = string.Empty;
Now the string.Empty
the actuall code for it is
static String()
{
Empty = "";
}
Meaning that you assign the string "" after compile time.
txtUserName.Text = "";
Now here you just assign the "" string directly to the object on compile time.
Small side note txtUserName.Text = "";
is faster than txtUserName.Text = string.Empty;
Source