[英]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.