基于用户的选择,我们可以无限地调用该方法。如果用户按下键“ Y”,则调用该方法,否则退出控制台应用程序。
下面是代码:
namespace IR_CSharp
{
class Program
{
private void GetASCIIValue()
{
Console.WriteLine("Enter a value to get the ascii value: ");
int value = Console.Read();
Console.WriteLine("ASCII value is {0}", value);
Console.ReadKey();
}
static void Main(string[] args)
{
Program prog = new Program();
string choice = "0";
prog.GetASCIIValue();
}
}
}
答案 0 :(得分:0)
class Program
{
static void Main(string[] args)
{
ConsoleKeyInfo keyinfo;
do
{
Console.WriteLine("Enter a value to get the ascii value: ");
int value = Console.Read();
Console.WriteLine("ASCII value is {0}", value);
keyinfo = Console.ReadKey();
}
while (keyinfo.Key != ConsoleKey.Y);
}
}