This method is used to converts the specified Unicode code point into a UTF-16 encoded string.
Syntax:
public static string ConvertFromUtf32 (int utf32);
Here, utf32 is a 21-bit Unicode code point.
Return Value: This method returns a string consisting of one Char object or a surrogate pair of Char objects equivalent to the code point specified by the utf32 parameter.
Exception: This method returns the ArgumentOutOfRangeException if utf32 is not a valid 21-bit Unicode code point ranging from U+0 through U+10FFFF, excluding the surrogate pair range from U+D800 through U+DFFF.
Below programs illustrate the use of Char.ConvertFromUtf32(Int32) Method:
Example 1:
csharp
using System;
using System.Globalization;
class GFG {
public static void Main()
{
try {
int utf = 0x0042;
string value = Char.ConvertFromUtf32(utf);
Console.WriteLine( "value is {0}" , value);
}
catch (ArgumentOutOfRangeException e) {
Console.Write( "Exception Thrown: " );
Console.Write( "{0}" , e.GetType(), e.Message);
}
}
}
|
Example 2: For ArgumentOutOfRangeException
csharp
using System;
using System.Globalization;
class GFG {
public static void Main()
{
try {
int utf = 0x11FFFF;
Console.WriteLine( "0x11FFFF is exceeding the limit" );
string value = Char.ConvertFromUtf32(utf);
Console.WriteLine( "value is {0}" , value);
}
catch (ArgumentOutOfRangeException e) {
Console.Write( "Exception Thrown: " );
Console.Write( "{0}" , e.GetType(), e.Message);
}
}
}
|
Output
0x11FFFF is exceeding the limit
Exception Thrown: System.ArgumentOutOfRangeException
Reference:
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
27 Dec, 2022
Like Article
Save Article