C# | Char.Parse(String) Method Last Updated : 01 Feb, 2019 Comments Improve Suggest changes Like Article Like Report This method is used to convert the value of the specified string to its equivalent Unicode character. Syntax: public static char Parse (string s); Here, s is a string that contains a single character, or null. Return Value: This method returns a Unicode character equivalent to the sole character in s. Exceptions: ArgumentNullException: If s is null. FormatException: If the length of s is not 1. Below programs illustrate the use of Char.Parse(String) Method: Example 1: csharp // C# program to demonstrate the // Char.Parse(String) Method using System; class GFG { // Main Method public static void Main() { try { // calling Parse() Method get("1"); get("a"); get("@"); get("-"); } catch (ArgumentNullException e) { Console.Write("Exception Thrown: "); Console.Write("{0}", e.GetType(), e.Message); } catch (FormatException e) { Console.Write("Exception Thrown: "); Console.Write("{0}", e.GetType(), e.Message); } } // Defining get() method public static void get(string s) { // getting Unicode character // using Parse() Method char val = Char.Parse(s); // display the char value Console.WriteLine("Unicode character "+ "of string {0} is {1}", s, val); } } Output: Unicode character of string 1 is 1 Unicode character of string a is a Unicode character of string @ is @ Unicode character of string - is - Example 2: For ArgumentNullException csharp // C# program to demonstrate the // Char.Parse(String) Method using System; class GFG { // Main Method public static void Main() { try { // calling Parse() Method get("1"); get("a"); get("@"); get("-"); Console.WriteLine(""); Console.WriteLine("s is null"); get(null); } catch (ArgumentNullException e) { Console.Write("Exception Thrown: "); Console.Write("{0}", e.GetType(), e.Message); } catch (FormatException e) { Console.Write("Exception Thrown: "); Console.Write("{0}", e.GetType(), e.Message); } } // Defining get() method public static void get(string s) { // getting Unicode character // using Parse() Method char val = Char.Parse(s); // display the char value Console.WriteLine("Unicode character of"+ " string {0} is {1}", s, val); } } Output: Unicode character of string 1 is 1 Unicode character of string a is a Unicode character of string @ is @ Unicode character of string - is - s is null Exception Thrown: System.ArgumentNullException Example 3: For FormatException csharp // C# program to demonstrate the // Char.Parse(String) Method using System; class GFG { // Main Method public static void Main() { try { // calling Parse() Method get("1"); get("a"); get("@"); get("-"); Console.WriteLine(""); Console.WriteLine("The length of s is not 1."); get("null"); } catch (ArgumentNullException e) { Console.Write("Exception Thrown: "); Console.Write("{0}", e.GetType(), e.Message); } catch (FormatException e) { Console.Write("Exception Thrown: "); Console.Write("{0}", e.GetType(), e.Message); } } // Defining get() method public static void get(string s) { // getting Unicode character // using Parse() Method char val = Char.Parse(s); // display the char value Console.WriteLine("Unicode character of "+ "string {0} is {1}", s, val); } } Output: Unicode character of string 1 is 1 Unicode character of string a is a Unicode character of string @ is @ Unicode character of string - is - The length of s is not 1. Exception Thrown: System.FormatException Reference: https://docs.microsoft.com/en-us/dotnet/api/system.char.parse?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Char.Parse(String) Method rohitprasad3 Follow Improve Article Tags : C# CSharp-method CSharp-Char-Struct Similar Reads C# | Char.IsDigit() Method In C#, Char.IsDigit() is a System.Char struct method which is used to check whether a Unicode character can be categorized as a decimal digit(radix 10) or not. Valid digits will be the members of the UnicodeCategory.DecimalDigitNumber category. This method can be overloaded by passing different type 3 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 C# | Char.IsLetter() Method In C#, Char.IsLetter() is a System.Char struct method which is used to check whether a Unicode character can be categorized as a Unicode letter or not. Unicode letters consist of the Uppercase letters, Lowercase letters, Title case letters, Modifiers letters and Other letters. This method can be ove 3 min read C# | Char.IsLetterOrDigit() Method In C#, Char.IsLetterOrDigit() is a System.Char struct method which is used to check whether a Unicode character can be categorized as a letter or decimal digit. Valid letters and decimal digits will be the members of the UnicodeCategory: UppercaseLetter, LowercaseLetter, TitlecaseLetter, ModifierLet 3 min read C# | Char.IsLower() Method In C#, Char.IsLower() is a System.Char struct method which is used to check whether a Unicode character can be categorized as a lowercase letter or not. Valid lowercase letters will be the members of UnicodeCategory: LowercaseLetter. This method can be overloaded by passing different type and number 3 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.IsNumber() Method In C#, Char.IsNumber() is a System.Char struct method which is used to check whether a Unicode character can be categorized as a number or not. Valid numbers will be the members of the UnicodeCategory.DecimalDigitNumber, UnicodeCategory.LetterNumber, or UnicodeCategory.OtherNumber category. This met 3 min read C# | Char.IsPunctuation() Method In C#, Char.IsPunctuation() is a System.Char struct method which is used to check whether an Unicode character can be categorized as a punctuation mark or not. This method can be overloaded by passing different type and number of arguments to it. Char.IsPunctuation(Char) Method Char.IsPunctuation(St 3 min read C# | Char.IsSeparator ( ) Method In C#, Char.IsSeparator() is a System.Char struct method which is used to check whether a Unicode character can be categorized as a separator character or not. This method can be overloaded by passing different type and number of arguments to it. Char.IsSeparator(Char) MethodChar.IsSeparator(String, 3 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 Like