this is my program that i wrote in C# in visual studio 2010 Ultimate and 2008 Team System:
class Program
{
static void Main(string[] args)
{
int a=0;
Console.WriteLine("Enter a number: ");
a = Console.Read();
Console.WriteLine("you Entered : {0}",a);
Console.ReadKey();
}
}
And this is the result:
Enter a number: 5 you Entered : 53
How this possible?
As the documentation clearly states,
Read()
returns the index of the Unicode codepoint that you typed.Try this to reach your goal:
I'm new to C#, but as far as I know, it's unnecessary to initialize your variable a when you create it. Another way to write your code could be:
Converted to a character code. Try:
The behavior you observed is described in the documentation.