Code Fix

初級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

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

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

not all code paths return a value の原因と直し方

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

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