I think the
string.IsNullOrWhiteSpace
method can be used with .Net 4 or above and
string.IsNullOrEmpty
method can be used with .Net 2.0 or 3.5.
if (string.IsNullOrWhiteSpace(txtDate.Text))
txtDate.Text = "0";
if (string.IsNullOrEmpty(txtDate.Text.Trim()))
txtDate.Text = "0";
It is preferable to use
string.IsNull...
method as it will not throw error when the
text
to be tested is
null
. On the other hand
text == ""
or
text == string.Empty
throws error if
text
is null.