初級 › does not exist in the current context の原因と直し方 › パターン2
does not exist in the current context の原因と直し方
変数名のスペルミスやスコープ外参照で出る、初心者に最も身近なエラーの一つです。
1 class Program { 2 static void Main(string[] args) { 3 if (true) { 4 int total = 100; 5 } 6 System.Console.WriteLine(_______); ^ 7 } 8 }
Program.cs(6,34): error CS0103: The name 'total' does not exist in the current context
空欄を埋めてビルドを通す
ブロック内で宣言した変数はそのブロックを出ると存在しません。スコープの外からは参照できません。
次の問題