settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Assign character variable (char) with the symbol that has Unicode code in C#

+4 votes

Please help me declare a character variable (char) and assign it with the symbol that has Unicode code 42 (decimal) using the '\u00XX' syntax, and then print it in C#.

The output must be * symbol

Thanks!

asked in C# category by user Jolie Ann

1 Answer

+2 votes
 
Best answer

Firstly you must, use the Windows calculator to find the hexadecimal representation of 42. It is 2A

Then use the Unicode code  syntax '\u00XX' - so it will look like \u002A (escape sequence). Do not forget to put it in single quotes (strings are in double qoutes)!

and then write the code itself:

using System;

class UnicodeCharacter
{
    static void Main()
    {
        char a = '\u002A';
        Console.WriteLine(a);
    }
}
answered by user john7
edited by user golearnweb
...