GeekInterview.com
Series: Subject: Topic:
Question: 424 of 460

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.

Asked by: Interview Candidate | Asked on: Sep 13th, 2004
Showing Answers 1 - 1 of 1 Answers
sahu

Answered On : Jan 8th, 2006

View all questions by sahu   View all answers by sahu

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.

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.