Use of IsNullOrWhiteSpace

Madhu.b.rokkam
Posted by Madhu.b.rokkam under C# category on | Points: 40 | Views : 3415
In C# 4.0 we can check whether

1. String is null.
2. String is empty.
3. String contains nothing but whitespace.

All these can be achieved by using string.IsNullOrWhiteSpace

static void Main(string[] args)
{
string value1 = " ";
Console.WriteLine(string.IsNullOrWhiteSpace(value1));

string value2 = "";
Console.WriteLine(string.IsNullOrWhiteSpace(value2));

string value3 = null;
Console.WriteLine(string.IsNullOrWhiteSpace(value3));

Console.Read();
}


Result

True
True
True

Comments or Responses

Login to post response