我看过其他问题,但是答案似乎太复杂了,无法理解,所以这是我的代码:
注意:我是C Shar语言的新手
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Input_Program
{
class Program
{
private static void Main()
{
Console.WriteLine("Welcome to my bool program!");
Console.WriteLine("Input a NON capital y or n when told to.");
char Y;
char N;
if(Y = 'y')
{}
}
}
}
谢谢
谢谢
最佳答案
您缺少等号:if(Y == 'y')
现在,将值'y'
分配给Y
,这也是赋值表达式的结果。这是一个char
,而编译器期望的是bool
结果。
更新:
当然,如thephpdeveloper所说,编译器还将坚持要求您在读取Y
之前为其分配一个值。所以:
char Y = 'y';
char N = 'n';
if(Y == 'y')
{}
关于c# - 错误1无法将类型'char'隐式转换为'bool',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5399972/