C# | Char.ConvertToUtf32(String, Int32) Method Last Updated : 05 Dec, 2019 Comments Improve Suggest changes Like Article Like Report This method is used to converts the value of a UTF-16 encoded character or surrogate pair at a specified position in a string into a Unicode code point. Syntax: public static int ConvertToUtf32 (string s, int index); Parameters: s: A string that contains a character or surrogate pair. index: The index position of the character or surrogate pair in s. Return Value: This method returns the 21-bit Unicode code point represented by the character or surrogate pair at the position in the s parameter specified by the index parameter. Exceptions: ArgumentNullException: If s is null. ArgumentOutOfRangeException: if index is not a position within s. Argument Exception: If the index is not a position within s. ArgumentException: If the specified index position contains a surrogate pair, and either the first character in the pair is not a valid high surrogate or the second character in the pair is not a valid low surrogate. Below programs illustrate the use of Char.ConvertToUtf32(String, Int32) Method: Example 1: csharp // C# program to demonstrate // Char.ConvertToUtf32(String, Int32) // Method using System; using System.Globalization; class GFG { // Main Method public static void Main() { try { // declaring and initializing int // variable with 21 bit unicode int utf = 0xF42; // getting the value // using ConvertFromUtf32() string value = Char.ConvertFromUtf32(utf); // getting unicode point // using ConvertToUtf32() method int val = Char.ConvertToUtf32(value, 0); // Display the value Console.WriteLine("value is 0x{0:X}", val); } catch (ArgumentOutOfRangeException e) { Console.Write("Exception Thrown: "); Console.Write("{0}", e.GetType(), e.Message); } } } Output: value is 0xF42 Example 2: For ArgumentOutOfRangeException csharp // C# program to demonstrate // Char.ConvertToUtf32(String, Int32) // Method using System; using System.Globalization; class GFG { // Main Method public static void Main() { try { // declaring and initializing int // variable with 21 bit unicode int utf = 0x42F; // getting the value // using ConvertFromUtf32() string value = Char.ConvertFromUtf32(utf); // getting unicode point // using ConvertToUtf32() method Console.WriteLine("index is not a position within s."); int val = Char.ConvertToUtf32(value, 0xDFFF); // Display the value Console.WriteLine("value is 0x{0:X}", val); } catch (ArgumentOutOfRangeException e) { Console.Write("Exception Thrown: "); Console.Write("{0}", e.GetType(), e.Message); } } } Output: index is not a position within s. Exception Thrown: System.ArgumentOutOfRangeException Example 3: For ArgumentNullException csharp // C# program to demonstrate // Char.ConvertToUtf32(String, Int32) // Method using System; using System.Globalization; class GFG { // Main Method public static void Main() { try { // declaring and initializing // int variablewith 21 bit // unicode int utf = 0x42F; // getting the value // using ConvertFromUtf32() string value = null; // getting unicode point // using ConvertToUtf32() method Console.WriteLine("string value is null"); int val = Char.ConvertToUtf32(value, 0); // Display the value Console.WriteLine("value is 0x{0:X}", val); } catch (ArgumentNullException e) { Console.Write("Exception Thrown: "); Console.Write("{0}", e.GetType(), e.Message); } catch (ArgumentOutOfRangeException e) { Console.Write("Exception Thrown: "); Console.Write("{0}", e.GetType(), e.Message); } catch (ArgumentException e) { Console.Write("Exception Thrown: "); Console.Write("{0}", e.GetType(), e.Message); } } } Output: string value is null Exception Thrown: System.ArgumentNullException Reference: https://docs.microsoft.com/en-us/dotnet/api/system.char.converttoutf32?view=netframework-4.7.2#System_Char_ConvertToUtf32_System_String_System_Int32_ Comment More infoAdvertise with us Next Article C# | Char.ConvertToUtf32(String, Int32) Method rohitprasad3 Follow Improve Article Tags : C# CSharp-method CSharp-Char-Struct Similar Reads C# | Convert.FromBase64String(String) Method This method is used to convert the specified string, which encodes binary data as base-64 digits, to an equivalent 8-bit unsigned integer array. Syntax: public static byte[] FromBase64String (string s); Here, s is the string to convert. Return Value: This method returns an array of 8-bit unsigned in 4 min read C# | Char.ToString() Method In C#, Char.ToString() is a System.Char struct method which is used to convert the value of this instance to its equivalent string representation. This method can be overloaded by passing different type of arguments to it. Char.ToString(IFormatProvider) Method Char.ToString(Char) Method Char.ToStrin 2 min read C# | Int32.ToString Method | Set - 2 Int32.ToString Method is used to convert the numeric value of the current instance to its equivalent string representation. There are 4 methods in the overload list of this method as follows: ToString(IFormatProvider) Method ToString(String, IFormatProvider) Method ToString() Method ToString(String) 2 min read C# | Int32.ToString Method | Set - 1 Int32.ToString Method is used to converts the numeric value of the current Int32 instance to its equivalent string representation. There are 4 methods in the overload list of this method as follows:Here, we will discuss the first two methods. ToString(IFormatProvider) Method This method is used to c 2 min read C# | Convert.ToBase64String() Method | Set-1 Convert.ToBase64String() Method is used to convert the value of an array of 8-bit unsigned integers to its equivalent string representation which is encoded with base-64 digits. There are 4 methods in the overload of this method which are as follows: ToBase64String(Byte[], Int32, Int32) Method ToBas 4 min read Convert a Character to the String in C# Given a character, the task is to character to the string in C#. Examples: Input : X = 'a' Output : string S = "a" Input : X = 'A' Output : string S = "A" Approach: The idea is to use ToString() method, the argument is the character and it returns string converting Unicode character to the string. / 1 min read C# | Convert.ToByte(String, IFormatProvider) Method This method is used to convert the specified string representation of a number to an equivalent 8-bit unsigned integer, using specified culture-specific formatting information.Syntax: public static byte ToByte (string value, IFormatProvider provider); Parameters: value: It is a string that contains 4 min read C# | Char.Parse(String) Method 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 3 min read C# | Convert.ToChar(String, IFormatProvider) Method This method is used to convert the value of the specified object to its equivalent Unicode character, using the specified culture-specific formatting information. Syntax: public static char ToChar (object value, IFormatProvider provider); Parameters: value: It is an string of length 1 or null. provi 3 min read C# | Convert.ToInt32(String, IFormatProvider) Method This method is used to converts the specified string representation of a number to an equivalent 32-bit signed integer, using the specified culture-specific formatting information. Syntax: public static int ToInt32 (string value, IFormatProvider provider); Parameters: value: It is a string that cont 4 min read Like