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("\nदबाने के लिए एक कुंजी दबाएं; " + "'Q' कुंजी दबाकर छोड़ें।");
while (Console.KeyAvailable == false) Thread.Sleep(100);
cs = Console.ReadKey(true);
Console.WriteLine("आपने '{0}' कुंजी दबाई।", 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("\nदबाने के लिए एक कुंजी दबाएं; " + "'P' कुंजी दबाकर छोड़ें।");
while (Console.KeyAvailable == false) Thread.Sleep(200);
cs = Console.ReadKey(true);
Console.WriteLine("आपने '{0}' कुंजी दबाई।", cs.Key)
} while (cs.Key != ConsoleKey.Q);
}
}
आउटपुट
यह निम्नलिखित आउटपुट देगा:
