c# - 无法使用布尔值获得特定输出
问题描述
我想要一个特定的输出,具体取决于布尔值是否设置为真。我似乎找不到解决方案,所以我只是在这里问。我不输出“真”或“假”,而是输出特定文本。
我尝试了什么:
public class Program
{
bool isAlive = true;
public static void Main()
{
if (isAlive == true){
Console.WriteLine("Is True");
}
}
}
什么有效:
public class Program
{
public static void Main()
{
bool isAlive = true;
if (isAlive == true){
Console.WriteLine("Is True");
}
}
}
The Error was that I tried to use the non-static variable in the static void. Thanks to everyone that helped.
解决方案
您可以使用以下代码
{boolean_variable} ?“布尔值为真”:“布尔值为假”
推荐阅读
- r - 我怎样才能有下拉“输入块”?
- javascript - 为什么匿名函数不能作为默认值的函数参数?
- push-notification - 使用 Firebase 为每个用户设备自定义推送通知设置
- windows - 使用 windows Installer 进行 Chrome 安装?
- nativescript - ios发布构建代码签名不起作用
- python - Django中的NoReverseMatch?
- java - JAVA get request with authorization header value
- tensorflow - 输入值范围与损失收敛之间的联系
- php - 如何使用 Symfony 3.4 组件更新实体
- kotlin - 无法返回 http 请求的正文