我正在寫一個控制檯程序,要求輸入姓名和年齡,然後確定您是否足夠長。我試圖用一個變量來確定該人可能着手:在當前的情況下名稱門不存在
Bool door = true;
那我想問,如果他們想再次填滿它在誰被剝奪,因爲他們的年齡的人。
if (door == false){
Console.WriteLine("Wilt u op nieuw uw leeftijd invullen?");
}
但Visual Studio中給了我以下錯誤:
Error CS0103 The name 'door' does not exist in the current context ConsoleApplication1
下面是完整的代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Hallo, wie ben jij? ");
string Name = Convert.ToString (Console.ReadLine());
Console.Write("Hallo " + Name + ", hoe oud ben jij? ");
int Age = Convert.ToInt32 (Console.ReadLine());
Console.ReadLine();
if (Age < 18) {
int remaining = 18 - Age;
Console.WriteLine("Helaas bent u nog geen achttien, U moet nog: "+remaining+" Jaar wachten.");
Console.ReadLine();
} else if (Age == 18) {
Console.WriteLine("U mag net door");
bool door = true;
Console.ReadLine();
} else {
Console.WriteLine("U bent door naar de volgende ronde");
bool door = true;
Console.ReadLine();
}
if (door == false)
{
Console.WriteLine("Wilt u op nieuw uw leeftijd invullen?");
}
}
}
}
門在if-else語句中定義;那麼它在該語句之外使用。在類的範圍內定義它(不在任何循環/ if語句中) –
Welkom in de wereld van C#! –