C# String IsNullOrEmpty() Method Last Updated : 25 Mar, 2025 Comments Improve Suggest changes Like Article Like Report In C#, IsNullOrEmpty() is a string method. It is used to check whether the specified string is null or an Empty string. A string will be null if it has not been assigned a value. A string will be empty if it is assigned “” or String.Empty (A constant for empty strings).Example 1: Using IsNullOrEmpty() to check whether the string is Null or empty. C# // C# program to demonstrate the use of // String.IsNullOrEmpty() method using System; class Geeks { static void Main(string[] args) { // Empty String string s1 = ""; // Non-Empty String string s2 = "Geek"; // Check for null or empty string bool res = String.IsNullOrEmpty(s1); // Display the result Console.WriteLine($"\"{s1}\" is null or empty: {res}"); res = String.IsNullOrEmpty(s2); // Display the result Console.WriteLine($"\"{s2}\" is null or empty: {res}"); } } Output"" is null or empty: True "Geek" is null or empty: False Syntax:public static bool IsNullOrEmpty(String str) Parameter: It takes a single parameter str, which is of type System.String Return-Type: Returns a boolean value. If the str parameter is null or an empty string (“”) then return True otherwise return False.Note: The IsNullOrEmpty method is used to check whether a string is either null or empty ("").A simple alternative to IsNullOrEmpty() can be written as:return s == null || s == String.Empty; This alternative works similarly but lacks the built-in optimization and clarity of IsNullOrEmpty().Example 2: Demonstrating a similar method to IsNullOrEmpty() and its internal workings. C# // C# program to illustrate an // alternative method for IsNullOrEmpty() using System; class Geeks { // Custom method similar to IsNullOrEmpty() public static bool Check(string s) { return s == null || s == String.Empty; // Equivalent to IsNullOrEmpty() } // Main Method public static void Main(string[] args) { string s1 = "GeeksforGeeks"; // Declare an empty string string s2 = ""; // Declare a null string string s3 = null; bool b1 = Check(s1); bool b2 = Check(s2); bool b3 = Check(s3); // Display the result Console.WriteLine(b1); Console.WriteLine(b2); Console.WriteLine(b3); } } OutputFalse True True Comment More infoAdvertise with us Next Article C# String IsNullOrEmpty() Method M Mithun Kumar Follow Improve Article Tags : C# CSharp-string CSharp-method Similar Reads C# | String.IsNormalized Method IsNormalized() method is used to check whether the given string is in a particular Unicode normalization form or not. If the given string is in the particular normalized form, then this method returns true. Otherwise, return false. There are two methods in the overload list of this method as follows 3 min read C# | IsNullOrWhiteSpace() Method In C#, IsNullOrWhiteSpace() is a string method. It is used to check whether the specified string is null or contains only white-space characters. A string will be null if it has not been assigned a value or has explicitly been assigned a value of null. Syntax: public static bool IsNullOrWhiteSpace(S 2 min read C# | String.Contains() Method In C#, the String.Contains() method is used to check whether a substring exists within a given string. It returns a Boolean value (true or false) indicating whether the substring is found. By default, the method performs a case-sensitive comparison.Example 1: Here, we are using the String.Contains() 3 min read C# String EndsWith() Method In C#, the EndsWith() is a string method used to check whether the ending of the current string instance matches a specified string. If it matches, it returns true; otherwise, it returns false. Using the foreach loop, we can check multiple strings. This method supports overloading by passing differe 4 min read C# String.IndexOf( ) Method | Set - 1 In C#, the IndexOf() method is a String method. Used to find the zero-based index of the first occurrence of a specified character or string within the current instance of the string. The method returns -1 if the character or string is not found. This method can be overloaded by passing different pa 6 min read C# | Char.IsLowSurrogate(String, Int32) Method This method is used to indicates whether the Char object at the specified position in a string is a low surrogate or not. Syntax: public static bool IsLowSurrogate (string s, int index); Parameters: s: It is a String. index: It is the character position to evaluate in s. Return Value: This method re 4 min read C# | Char.IsSurrogate(String, Int32) Method This method is used to indicates whether the character at the specified position in a specified string has a surrogate code unit or not. Syntax: public static bool IsSurrogate (string s, int index); Parameters: s: It is a String. index: It is the character position to evaluate in s. Return Value: Th 4 min read C# | Char.IsControl(String, Int32) Method This method is used to indicates whether the character at the specified position in a specified string is categorized as a control character. Syntax: public static bool IsControl (string s, int index); Parameters: s: It is the String. index: It is the character position in s. Return Value: This meth 3 min read C# | Char.IsSurrogatePair(String, Int32) Method This method is used to indicates whether two adjacent Char objects at a specified position in a string form a surrogate pair or not. Syntax: public static bool IsSurrogatePair (string s, int index); Parameters: s: It is a String. index: It is the starting position of the pair of characters to evalua 4 min read C# | Char.IsHighSurrogate(String, Int32) Method This method is used to indicates whether the Char object at the specified position in a string is a high surrogate or not. Syntax: public static bool IsHighSurrogate (string s, int index); Parameters: s: It is a String. index: It is the character position in s. Return Value: This method returns true 4 min read Like