当用户输入“停止”时,如何停止程序(c#console)

时间:2017-12-04 14:58:08

标签: c#

the question with image

这是我的代码,我在代码中解释了所有内容。

import { File } from '@ionic-native/file';

1 个答案:

答案 0 :(得分:1)

在你的函数中(我想它是应用程序入口点):

while (true)
{
    String line = Console.ReadLine();

    if ((line == null) || (line.ToLowerInvariant() == "stop"))
        break;

    // implement your logic here... for example, if you want to print
    // a word at once even if the user entered multiples:

    String[] split = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

    for (Int32 i = 0 ; i < split.Length; ++i)
        Console.WriteLine(split[i]);
}