根据用户选择循环方法调用

时间:2019-04-17 07:57:10

标签: c#

基于用户的选择,我们可以无限地调用该方法。如果用户按下键“ 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();
        }
    }
}

1 个答案:

答案 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);
    }
}