The text box in question is involved in an if statement within my code, something to the effect of
if (textbox.text != "")
{
do this
}
I am curious if an empty text box will be considered an empty string or a null statement.
The text box in question is involved in an if statement within my code, something to the effect of
if (textbox.text != "")
{
do this
}
I am curious if an empty text box will be considered an empty string or a null statement.
It will be an empty string but better to check with this IsNullOrEmpty or IsNullOrWhiteSpace
IsNullOrWhiteSpace is also take care of whitespace in input string. So if you don't want to execute the code for whitespace too then use second option.
Try to use
IsNullOrWhiteSpace
, this will make sure of validating the whitespace too without having to trim it.According to documentation
string.IsNullOrWhiteSpace
evaluates to:String.IsNullOrWhiteSpace:
In short it will be an empty string, but you could use the debugger and check that yourself.
However for best practice use
IsNullOrEmpty
orIsNullOrWhiteSpace
Alternatively:
http://msdn.microsoft.com/en-us/library/system.string.isnullorwhitespace.aspx
if (textbox.text != "" || textbox.text != null)
It will be considered an empty string.