简体   繁体   English

为什么这个 bool 不能识别正在使用?

[英]Why does this bool not recognize being used?

I've made an example of typing in first and last name.我做了一个输入名字和姓氏的例子。 Why doesn't the assigned variable "EmptyInput" recognize it's being used even though I've added a false and true value?为什么即使我添加了 false 和 true 值,分配的变量“EmptyInput”也不能识别它正在被使用? I don't know what the green wavy line underneath is called.我不知道下面的绿色波浪线叫什么。

using System.Collections.Generic;
using System;
using System.Threading;

namespace MyLogbook
{
    public static class Program
    {
        class PInfo
        {
            public string FirstName;
            public string LastName;
        }
        public static void Main(string[] args)
        {

        Console.WriteLine("\tWelcome to your new logbook!");
            Console.WriteLine("\tPlease enter your first and last name.\n");

            PInfo pInfo = new PInfo();
            bool EmptyInput;
            do
            {
                Console.Write("\tFirst name: ");
                pInfo.FirstName = Console.ReadLine();

                Console.Write("\tLast name: ");
                pInfo.LastName = Console.ReadLine();

                if (!string.IsNullOrEmpty(pInfo.FirstName + pInfo.LastName))
                {
                    Console.WriteLine("\n\tHi, " + pInfo.FirstName + " " + pInfo.LastName + ".\n");
                    EmptyInput = false;
                }
                else
                {
                    Console.Write("\n\tEmpty input, please try again.\n\n");
                    EmptyInput = true;
                }
            } while (string.IsNullOrEmpty(pInfo.FirstName + pInfo.LastName));
        }
    }
}

Maybe you mean to do this也许你的意思是这样做

} while (EmptyInput);

instead of代替

} while (string.IsNullOrEmpty(pInfo.FirstName + pInfo.LastName));

because you're just assigning value to the variable, but never using it因为你只是给变量赋值,但从不使用它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更新没有锁保护的线程正在使用的bool值 - Update a bool value being used by a thread without lock protection XmlSerializer为什么不能识别此属性? - Why does not XmlSerializer recognize this attribute? 为什么这个静态bool不需要初始化? - Why does this static bool not need to be initialized? 为什么将此数字检测为布尔值? - Why does this number gets detected as bool? 为什么这个简单的 bool 赋值会产生错误 - Why does this simple assignment of a bool generate an error 为什么编译器将bool转换为整数然后又返回bool而不是返回bool本身? - Why does the compiler convert bool to integer and back to bool instead of returning the bool itself? 为什么在不使用可空bool的情况下设置bool的值时可以使用null条件运算符? - Why can the null conditional operator be used when setting the value of a bool without using a nullable bool? 为什么:LINQ 到实体不识别的方法? - Why: LINQ to Entities does not recognize the method? 为什么IsKnownColor无法识别所有颜色? - Why does IsKnownColor not recognize all colors? 为什么 PEVerify 无法识别有效代码? - Why does PEVerify not recognize valid code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM