Console.WriteLine("{0}", true);
Console.WriteLine("{0}", !true);
Console.WriteLine("{0}", true == true);
Console.WriteLine("{0}", true == flase);
Console.WriteLine("{0}", true != false);
Console.WriteLine("{0}", true && false);
Console.WriteLine("{0}", true || false);
Console.WriteLine("{0}", true ^ false);
Console.WriteLine("{0}", false ^ false);
Console.WriteLine("{0}", 1 == 1);
Console.WriteLine("{0}", 1 != 2);
Console.WriteLine("{0}", 1 < 2);
Console.WriteLine("{0}", 1 <= 1);
Console.WriteLine("{0}", 1 > 2);
Console.WriteLine("{0}", 1 >= 2);
Console.WriteLine("{0}", 1+1 == 2);
Console.WriteLine("{0}", 1+1 > 2);
如果
if(條件)
{
//條件為真則會做
}
bool isGirl = true;
Console.WriteLine("Line1");
if(isGirl)
{
Console.WriteLine("She is a girl: {0}", isGirl);
}
Console.WriteLine("Line2 or line3?");
如果、其餘
if(條件)
{
//條件為真則會做
}
else
{
//其餘的會做
}
bool isGirl = false;
Console.WriteLine("Line1");
if(isGirl)
{
Console.WriteLine("She is a girl: {0}", isGirl);
}
else
{
Console.WriteLine("She isn't a girl: {0}", isGirl);
}
Console.WriteLine("Line2, line3 or line4?");
如果、其餘之中如果、其餘
if(條件一)
{
//條件一為真則會做
}
else if(條件二)
{
//條件一不為真但條件二為真則會做
}
...
else
{
//其餘的
}
int score = 83;
Console.WriteLine("Line1");
if(score == 100)
{
Console.WriteLine("Excellent!");
}
else if(score >= 90)
{
Console.WriteLine("Great!");
}
else if(score >= 70)
{
Console.WriteLine("Not bad!");
}
else if(score >= 60)
{
Console.WriteLine("Fine");
}
else
{
Console.WriteLine("Bad...");
}
Console.WriteLine("The score: {0}", score);
執行結果?
bool isBoy = true;
bool isCute = true;
if(isBoy)
{
if(isCute)
{
Console.Write("這麼可愛一定是男孩子!");
}
else
{
Console.WriteLine("唉呀,是個小正太~");
}
}
else
{
if(isCute)
{
Console.WriteLine("是ㄌㄌ!");
}
else
{
Console.WriteLine("成熟性感美麗的大姊姊>/////<");
}
}
Random rd1 = new Random();
Random rd2 = new Random();
Console.WriteLine("First: {0}, {1}, {2}, {3}", rd1.Next(), rd1.Next(), rd1.Next(), rd1.Next());
Console.WriteLine("Second: {0}, {1}, {2}, {3}", rd2.Next(), rd2.Next(), rd2.Next(), rd2.Next());
Random rd1 = new Random(Guid.NewGuid().GetHashCode());
Random rd2 = new Random(Guid.NewGuid().GetHashCode());
Console.WriteLine("First: {0}, {1}, {2}, {3}", rd1.Next(), rd1.Next(), rd1.Next(), rd1.Next());
Console.WriteLine("Second: {0}, {1}, {2}, {3}", rd2.Next(), rd2.Next(), rd2.Next(), rd2.Next());
Console.WriteLine("First: {0}, {1}, {2}, {3}", rd1.Next(3), rd1.Next(3), rd1.Next(3), rd1.Next(3));
Console.WriteLine("Second: {0}, {1}, {2}, {3}", rd2.Next(4, 6), rd2.Next(4, 6), rd2.Next(4, 6), rd2.Next(4, 6));