Thursday, 8 August 2013

string null checking from different style

string null checking from different style

I don't know before this asked or not, but I am confuse in below of code
block.
CODE 1
if (String.IsNullOrEmpty(control.Text.Trim()))
{
// Code to execute
}
CODE 2
if (control.Text.Trim() == "")
{
// Code to execute
}
CODE 3
if (control.Text.Trim() == null)
{
// Code to execute
}
CODE 4
if (control.Text.Trim() == string.Empty)
{
// Code to execute
}
According to me all are working to me.
I just feeling wonder that what is the different in between in this 4 code
block.

No comments:

Post a Comment