C# में Console.KeyAvailable() प्रॉपर्टी का उपयोग यह इंगित करने के लिए किया जाता है कि इनपुट स्ट्रीम में एक कुंजी प्रेस उपलब्ध है या नहीं।
सिंटैक्स
वाक्य रचना इस प्रकार है -
public static bool KeyAvailable { get; } उदाहरण
आइए अब C# -
. में Console.KeyAvailable() प्रॉपर्टी को लागू करने के लिए एक उदाहरण देखेंusing System;
using System.Threading;
class Demo {
public static void Main (string[] args) {
ConsoleKeyInfo cs = new ConsoleKeyInfo();
do {
Console.WriteLine("\nPress a key to display; "+ "press the 'Q' key to quit.");
while (Console.KeyAvailable == false)Thread.Sleep(100);
cs = Console.ReadKey(true);
Console.WriteLine("You pressed the '{0}' key.", cs.Key);
}
while (cs.Key != ConsoleKey.Q);
}
} आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा -

उदाहरण
आइए अब C# -
. में Console.KeyAvailable() प्रॉपर्टी को लागू करने के लिए एक और उदाहरण देखेंusing System;
using System.Threading;
class Demo {
public static void Main (string[] args) {
ConsoleKeyInfo cs = new ConsoleKeyInfo();
do {
Console.WriteLine("\nPress a key to display; "+ "press the 'P' key to quit.");
while (Console.KeyAvailable == false)Thread.Sleep(200);
cs = Console.ReadKey(true);
Console.WriteLine("You pressed the '{0}' key.", cs.Key)
}
while (cs.Key != ConsoleKey.Q);
}
} आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा -
