Code Fix

初級Cannot implicitly convert type の原因と直し方 › パターン2

Cannot implicitly convert type の原因と直し方

暗黙的に変換できない型同士を代入しようとしたときに出ます。

 1  class Program {
 2      static void Main(string[] args) {
 3          int price = ___;
                         ^
 4          System.Console.WriteLine(price);
 5      }
 6  }
Program.cs(3,21): error CS0266: Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)

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

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

Cannot implicitly convert type の原因と直し方

string→intやbool→intなど、C#が許さない組み合わせを押さえておきましょう。

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

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