How can I get the ASCII code for a character in C#?

Casting the char to an int will give you the ASCII value: char c = 'f';

System.Console.WriteLine((int)c);

or for a character in a string: System.Console.WriteLine((int)s[3]);

The base class libraries also offer ways to do this with the Convert class or Encoding classes if you need a particular encoding.

Showing Answers 1 - 1 of 1 Answers

Ans:

// Create an ASCII encoding.
            Encoding ascii = Encoding.ASCII;

The base class libraries also offer ways to do this with the Convert class or Encoding classes if you need a particular encoding.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions