我如何读取布尔值?
How do i read a boolean value?
我正在制作我想制作的应用程序的基础,但是我在这个“原型”(我猜它是一个原型? )
string friend;
string friend2;
string friend3;
bool option;
Console.WriteLine("Who would you like to talk to first? " + friend + ", " + friend2 + ", " + friend3);
option = (Console.ReadLine);
if(option = friend)
{
}
这就是问题的代码。我应该删除它还是有人可以帮忙?
我觉得你有点糊涂了,你用的是赋值运算符而不是比较运算符。
举个例子
int a = 1 + 2 + 3;
int b = 6;
Console.WriteLine(a == b); // output: True
char c1 = 'a';
char c2 = 'A';
Console.WriteLine(c1 == c2); // output: False
Console.WriteLine(c1 == char.ToLower(c2)); // output: True
你也可以阅读这个https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/equality-operators
option
变量在您的情况下应为 string
类型。
然后,您需要更改此位(赋值运算符)
if(option = friend)
到这个(比较运算符)
if(option == friend)
所以最后你会得到(在 readline 命令修复之后)
string friend;
string friend2;
string friend3;
string option;
Console.WriteLine("Who would you like to talk to first? " + friend + ", " + friend2 + ", " + friend3);
option = Console.ReadLine();
if(option == friend)
{
}
玩得开心!
我正在制作我想制作的应用程序的基础,但是我在这个“原型”(我猜它是一个原型? )
string friend;
string friend2;
string friend3;
bool option;
Console.WriteLine("Who would you like to talk to first? " + friend + ", " + friend2 + ", " + friend3);
option = (Console.ReadLine);
if(option = friend)
{
}
这就是问题的代码。我应该删除它还是有人可以帮忙?
我觉得你有点糊涂了,你用的是赋值运算符而不是比较运算符。
举个例子
int a = 1 + 2 + 3;
int b = 6;
Console.WriteLine(a == b); // output: True
char c1 = 'a';
char c2 = 'A';
Console.WriteLine(c1 == c2); // output: False
Console.WriteLine(c1 == char.ToLower(c2)); // output: True
你也可以阅读这个https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/equality-operators
option
变量在您的情况下应为 string
类型。
然后,您需要更改此位(赋值运算符)
if(option = friend)
到这个(比较运算符)
if(option == friend)
所以最后你会得到(在 readline 命令修复之后)
string friend;
string friend2;
string friend3;
string option;
Console.WriteLine("Who would you like to talk to first? " + friend + ", " + friend2 + ", " + friend3);
option = Console.ReadLine();
if(option == friend)
{
}
玩得开心!