Showing posts with label check string if empty or null. Show all posts
Showing posts with label check string if empty or null. Show all posts

Sunday, May 20, 2018

How To Check if a String or TextBox is Empty or Null in C#

To check if a string or textbox is empty, simply follow the code snippet below.

if (!string.IsNullOrEmpty(textboxName.Text)
{
   //This will if a textbox is not empty
}

if (!string.IsNullOrEmpty(stringName)
{
   //This will if a string variable is not empty
}