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