Code Fix

初級Use of unassigned local variable の原因と直し方 › パターン3

Use of unassigned local variable の原因と直し方

ローカル変数は宣言しただけでは値を持ちません。

 1  class Program {
 2      static void Main(string[] args) {
 3          int a;
 4          if (args.Length > 0) {
 5              a = 1;
 6          }
 7          System.Console.WriteLine(__);
                                      ^
 8      }
 9  }
Program.cs(7,34): error CS0165: Use of unassigned local variable 'a'

空欄を埋めてビルドを通す

広告
広告スロット(未設定)

Use of unassigned local variable の原因と直し方

条件分岐をまたいだ使用で見落としがちなエラーです。

このエラーの解説と類題をまとめて見る →

広告
広告スロット(未設定)