Basic C#

hello,
i am a beginner in c#.

the program should show de pressd key "the pressd key is b" forexample

int I;
Console.WriteLine("press a key");


i know the WriteLine will display the string "press a key" but i dont knwo how i can get the pressd key in to my variable I , so i can show it to the screen "the press key is b" forexample

thank you
kensy11Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ToddBeaulieuConnect With a Mentor Commented:
writeline OUTPUTs. Use ReadKey() for input. (single key)

            Console.WriteLine("Press any key:");
            ConsoleKeyInfo key = Console.ReadKey();
            if (key.Key == ConsoleKey.B)
            { }

0
 
AJRDevConnect With a Mentor Commented:
Hi,

You can use the ReadKey() method of the Console class. It returns a ConsoleKeyInfo object and you can access the Key property to see what was pressed. Note that if you want to check if any modifier keys were used (such as Shift, Alt, Ctrl, etc) you will need to perform that test separately.

ConsoleKeyInfo consoleKeyInfo = System.Console.ReadKey(true);
System.Console.WriteLine(consoleKeyInfo.Key.ToString());

Have a look at the MSDN example at http://msdn.microsoft.com/en-us/library/system.consolekeyinfo.aspx

0
All Courses

From novice to tech pro — start learning today.