TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Maha
NA
0
324.8k
Console.ReadKey
Jul 5 2013 3:22 PM
This program is given in following website.
http://www.dotnetperls.com/console-readkey
This new code (info.KeyChar == 'X') instead of (info.Key == ConsoleKey.X) is giving different last line output. Please explain the reason. Code is highlighted.
using System;
class Program
{
static void Main()
{
Console.WriteLine("... Press escape, a, then control X");
// Call ReadKey method and store result in local variable.
// ... Then test the result for escape.
ConsoleKeyInfo info = Console.ReadKey();
if (info.Key == ConsoleKey.Escape)
{
Console.WriteLine("You pressed escape!");
}
// Call ReadKey again and test for the letter a.
info = Console.ReadKey();
if (info.KeyChar == 'a')
{
Console.WriteLine("You pressed a");
}
// Call ReadKey again and test for control-X.
// ... This implements a shortcut sequence.
info = Console.ReadKey();
if (
info.Key == ConsoleKey.X
&& info.Modifiers == ConsoleModifiers.Control)
{
Console.WriteLine("You pressed control X");
}
Console.Read();
}
}
/*
... Press escape, a, then control X
?You pressed escape!
aYou pressed a
?You pressed control X
*/
Reply
Answers (
2
)
problem in list<>
ON c#