Mayur Lohite Published a new article on Web, Mobile & Software Dev, Mobile Development, Web Development, Web & Mobile Design
19-Oct-2019
Hello all,
We need to work on string operations quite often in projects. Many times we need to check if string is empty or null. Now there is difference in null and empty value.
In C# -
Here is example:
/* Goal: I need to check if string has some value (Not empty) Or NULL. */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IsNullOrEmptyDemo { class Program { static void Main(string[] args) { string emptyString = ""; string nullString = null; if (string.IsNullOrEmpty(emptyString)) { Console.WriteLine("emptyString - String is either null or does not contain any data."); } if (string.IsNullOrEmpty(nullString)) { Console.WriteLine("nullString - String is either null or does not contain any data."); } Console.ReadKey(); } } }