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)
{
As the documentation clearly states, Read()
returns the index of the Unicode codepoint that you typed.
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:
class Program
{
static void Main(string[] args)
{
int a;
Console.WriteLine("Enter a number: ");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("you Entered : {0}", a);
Console.ReadKey();
}
}
Try this to reach your goal:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a number: ");
ConsoleKeyInfo a = Console.ReadKey();
Console.WriteLine("you Entered : {0}",a.KeyChar);
Console.ReadKey();
}
}
Converted to a character code. Try:
a = int.Parse(Console.ReadLine());
The behavior you observed is described in the documentation.