Code Fix

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

Cannot implicitly convert type の原因と直し方

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

 1  class Program {
 2      static void Main(string[] args) {
 3          int n = ____;
                      ^
 4          System.Console.WriteLine(n);
 5      }
 6  }
Program.cs(3,17): error CS0029: Cannot implicitly convert type 'string' to 'int'

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

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

Cannot implicitly convert type の原因と直し方

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

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

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