c# - 为什么 if 语句中的这个字符串初始化会阻止我打印?

标签 c# syntax language-design if-statement

我对if没什么问题

{
    string nom;
    string ou;
    nom = "1";
    if (nom == "1")
    {
        nom +=1;
        ou = nom;
    }
    Console.Write(ou);
}

但是我不知道为什么我不能打印你的值

最佳答案

尝试这样的事情

{
    string nom;
    string ou = String.Empty;
    nom = "1";
    if (nom == "1")
    {
        nom +=1;
        ou = nom;
    }
    Console.Write(ou);
}

关于c# - 为什么 if 语句中的这个字符串初始化会阻止我打印?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/585543/

相关文章:

c# - 如何处理来自同一个异常对象的不同类型的异常?

c# - Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0 中存储了哪些文件?

c# - 如何读取 ASP.NET Core Response.Body?

SQL:将一个表中的所有记录插入到另一表中,而不指定列

iterator - 为什么Lua的迭代器是三元组?

c# - 为什么 View 设置为 Details 的 C# ListView 控件仍然为空?

python - 为什么 python 在某些事情上使用两个下划线?

r - 用as强制R中的类数据类型

c++ - 包含库的语言设计问题

c++ - 为什么 C++ 需要单独的头文件?