初級 › not all code paths return a value の原因と直し方 › パターン1
not all code paths return a value の原因と直し方
値を返すと宣言したメソッドで、すべての実行経路にreturn文があるかをコンパイラが検証します。
1 class Program { 2 static int Twice(int n) { 3 int r = n * 2; 4 _________ ^ 5 } 6 static void Main(string[] args) { 7 System.Console.WriteLine(Twice(3)); 8 } 9 }
Program.cs(2,16): error CS0161: 'Program.Twice(int)': not all code paths return a value
空欄を埋めてビルドを通す
int型を返すと宣言したメソッドは、すべての実行経路でreturn文が必要です。
次の問題