C# | Uri.HexEscape(Char) Method

Uri.HexEscape(Char) Method is used to convert a specified character into its hexadecimal equivalent.

Syntax: public static string HexEscape (char character);
Here, it takes the character to convert to hexadecimal representation.

Return Value: This method returns the hexadecimal representation of the specified character.

Exception: This method throws ArgumentOutOfRangeException if character is greater than 255.

Below programs illustrate the use of Uri.HexEscape(Char) Method:



Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate the
// Uri.HexEscape() Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
  
        // Declaring and initializing address1
        char ch = 'c';
  
        // Converting the specified character 
        // into its hexadecimal equivalent
        // using HexEscape() method
        string value = Uri.HexEscape(ch);
  
        // Displaying the result
        Console.WriteLine("Hexadecimal Equivalent is: {0}", value);
    }
}

chevron_right


Output:

Hexadecimal Equivalent is: %63

Note: Character greater than 255 is not practically possible.

Reference:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.