本文整理汇总了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;
}
示例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!");
}
示例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);
}
示例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;
}
示例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]);
}