c# - 如何检测 C# 中的特定单词

标签 c#

我不是编码员,也不是任何编码新手。我尝试执行 Console.ReadLine("stop") 然后执行 Console.End 但它不起作用。

Console.WriteLine("What's your name?");
Console.ReadLine();

Console.WriteLine("Cool! My Name Is Program Bot!");
Console.ReadLine("stop");
Console.End();

最佳答案

你需要赋值给一个变量然后检查条件

        Console.WriteLine("What's your name?");
        Console.ReadLine();

        Console.WriteLine("Cool! My Name Is Program Bot!");
        var output = Console.ReadLine();
        if (output == null || output == "stop") {
            Environment.Exit(0);
        }

您需要检查以下项目以了解什么是什么:

if/else statements -> 是您的代码决定如何做某事的方式。

c# variables -> var output 是变量声明,也可以是string output

c# methods -> Console.ReadLine() 是一个返回字符串值的方法

关于c# - 如何检测 C# 中的特定单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64290757/

相关文章:

c# - EF6 Linq - 如何创建相当于 "where(List == null || List.Contains(obj))"的过滤器表达式?

c# - 哪个优先 : Don't Repeat Yourself or the Single Responsibility Principle?

c# - 从 List<float> 转换为 int

c# - 如何检查 6 :00 PM to 9:00 PM 等字符串是否存在时间冲突

c# - "fluent"(或可链接)方法必须是不可变的吗?

c# - 如何在 visual studio 中获取文件的相对路径?

regex - 用于验证名称和姓氏的正则表达式?

c# - 随着时间的推移,DispatcherTimer 会占用 CPU,导致 WPF 视觉对象无法正确呈现

c# - 处理大型位图(最大 3GB)

c# - DbContext 仅在远程服务器上超时