Do you need to use this to check if field is null in C#
If (fieldName.Text == "" || fieldName.Text == null)
If so, what does each check, check for, or are they checking for the same thing?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Jan 26, 2013, 1:22 PM
If you have this:
string s = null;
then it means that the variable 's' doesn't currently refer to a string instance.
However, if you have this:
string s = "";
it means that 's' does refer to a string instance but that instance has no characters i.e. it's an empty string.
There is a convenience method that can be used to check for both:
if (String.IsNullOrEmpty(fieldName.Text))
{
// do something
}