我的C#代码出了什么问题? [英] what's wrong with my C# code?
问题描述
我这里没有得到任何输出。尝试了一些不同的变化 - 我没有错误,但没有输出。赋值是组合多个布尔值(false)以获得输出让我们走出去。任何帮助将不胜感激,以便快速解决问题。谢谢!
I am not getting any output here. Have tried a few different variations - I get no errors, but no output. The assignment is to combine multiple Boolean values (false) to get the output "Let's go outside." Any help would be appreciated for a quick fix. thank you!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace boolletsgooutside
{
class boolletsgooutside
{
static void Main(string[] args)
{
// declare boolean values
bool icyRain = true;
bool tornadoWarning = true;
string name = "Let's go outside";
if ((!icyRain) & (!tornadoWarning))
{
Console.WriteLine("{0}";, name);
}
}
}
}
推荐答案
如果查看代码
If you look at the code
static void Main(string[] args)
{
// declare boolean values
bool icyRain = false;
bool tornadoWarning = false;
if ((icyRain) && (tornadoWarning))
{
Console.WriteLine("Let's go outside!");
}
}
}
}
if条件将被评估为
if(false)&& (false),等于if(false)。
这意味着,只有else部分中的代码会在这里执行(遗憾的是你没有添加任何其他部分。
另外,请添加一个Console.Read()来保存控制台窗口,直到你按任意键!
The if condition will be evaluated as
if(false) && (false), which will be equal to if(false).
that means, only the code in the else part will be executed here (unfortunately you didn't add any else part.
Also, please add a Console.Read() to hold the console window, until you press any key!
谢谢你,非常感谢你的反馈。
我仍然要错过一些东西,因为如果我这样做,我仍然有同样的问题,没有输出。坦率地说,不管怎么样我玩过它,输出是空白的。我是初学者,所以我错过了一些东西。
static void Main(string [] args)
{
//声明布尔值
bool icyRain = false;
bool tornadoWarning = false;
if((icyRain)&&(tornadoWarning))
{
Console.WriteLine(我们出去吧! );
}
}
}
}
thank you, definitely appreciate the feedback.
I must still be missing something, because if I do it this way, I still have the same problem of no output. Frankly, no matter how I've played with it, the output is blank. I'm a beginner, so I am missing something.
static void Main(string[] args)
{
// declare boolean values
bool icyRain = false;
bool tornadoWarning = false;
if ((icyRain) && (tornadoWarning))
{
Console.WriteLine("Let's go outside!");
}
}
}
}
尝试使用逻辑和
Try with thelogical and
if ((!icyRain) && (!tornadoWarning))
否则,无输出完全正常,这就是你问的。
这可能更接近您的意图:
Otherwise, no output is perfectly normal, it is what you asked.
This may be closer to your intend:
bool icyRain = false;
bool tornadoWarning = false;
if ((!icyRain) && (!tornadoWarning))
这篇关于我的C#代码出了什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!