当前位置: 首页>>代码示例>>C#>>正文


C# IConsole.ReadLine方法代码示例

本文整理汇总了C#中IConsole.ReadLine方法的典型用法代码示例。如果您正苦于以下问题:C# IConsole.ReadLine方法的具体用法?C# IConsole.ReadLine怎么用?C# IConsole.ReadLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IConsole的用法示例。


在下文中一共展示了IConsole.ReadLine方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        public override void Execute(IConsole console)
        {
            int x = 1;
            string input;
            int option = -1;

            while (true)
            {
                console.WriteLine("****************************************");
                console.WriteLine("*\t" + _menu_header_text);
                console.WriteLine("****************************************");
                console.Write("\n\n");
                console.WriteLine("0 - Return");
                foreach (var entry in entries)
                {
                    console.WriteLine(x.ToString() + " - " + entry.menu_text);
                }

            
                while (option < 0)
                {
                    console.Write("Enter Selection: ");
                    try
                    {
                        input = console.ReadLine();
                    }
                    catch (IOException)
                    {
                        input = null;
                    }
                    if (input != null)
                    {
                        if (int.TryParse(input, out x))
                        {
                            if ((x >= 0) && (x <= entries.Count()))
                            {
                                option = x;
                                break;
                            }
                        }
                    }
                    console.WriteLine("\nInvalid selection");
                }

                if (option > 0)
                {
                    entries[option - 1].Execute(console);
                    option = -1;
                }
                else if (option == 0)
                    break;
            }
            return;
        }
开发者ID:ams-tech,项目名称:SpreadsheetsOnline,代码行数:54,代码来源:ConsoleMenu.cs

示例2: Main

        public static void Main(string[] args)
        {
            _controller = Container.Resolve<IController>();
            _console = Container.Resolve<IConsole>();

            string userInput;

            while ((userInput = _console.ReadLine()).ToLower() != "exit")
            {
                 _controller.Run(userInput);
            }

            _console.WriteLine("Good bye!");
        }
开发者ID:asierba,项目名称:barker,代码行数:14,代码来源:Program.cs

示例3: SetUp

        public void SetUp()
        {
            console = Substitute.For<IConsole>();
            console.ReadLine().Returns("input value");

            translator = Substitute.For<ITranslator>();
            translator.Translate("EnterFolderPath").Returns("{0}");

            solutionCloner = Substitute.For<ISolutionCloner>();

            routine = new CloneRoutine(console, translator, solutionCloner);
        }
开发者ID:daniellee,项目名称:Cloney,代码行数:12,代码来源:CloneRoutineBehavior.cs

示例4: ReadBoardSize

        /// <summary>
        /// Reads from the input the game size.
        /// </summary>
        /// <param name="userInput">the user UI handling object</param>
        /// <returns>the size of the game board</returns>
        public static int ReadBoardSize(IConsole userInput)
        {
            userInput.Write("Welcome to \"Battle Field game.\" Enter battlefield size: N = ");
            int gameBoardSize = Convert.ToInt32(userInput.ReadLine());
            while (gameBoardSize < 1 || gameBoardSize > 10)
            {
                userInput.WriteLine("Enter a number between 1 and 10!");
                gameBoardSize = Convert.ToInt32(userInput.ReadLine());
            }

            return gameBoardSize;
        }
开发者ID:venelin-p-petrov,项目名称:Battle-Field-1-Telerik-Team-Strontium,代码行数:17,代码来源:GameEngine.cs

示例5: EnterCoordinates

 /// <summary>
 /// Reads from the input the coordinates for the next turn
 /// </summary>
 /// <param name="row">the entered row will be saved here</param>
 /// <param name="col">the entered col will be saved here</param>
 /// <param name="userInput">the user UI handling object</param>
 private static void EnterCoordinates(out int row, out int col, IConsole userInput)
 {
     userInput.WriteLine("Please enter coordinates: ");
     string[] mineCoordinates = userInput.ReadLine().Split(new char[] { ' ', ',' },
         StringSplitOptions.RemoveEmptyEntries);
     row = int.Parse(mineCoordinates[0]);
     col = int.Parse(mineCoordinates[1]);
 }
开发者ID:venelin-p-petrov,项目名称:Battle-Field-1-Telerik-Team-Strontium,代码行数:14,代码来源:GameEngine.cs


注:本文中的IConsole.ReadLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。