プログラミング初学者です。
特にC#は始めたばかりです。
以下のプログラミングを実行するとエラーが出ます。
using
1using System.Collections.Generic; 2using System.Linq; 3using System.Text; 4using System.Threading.Tasks; 5 6namespace BookProblem204_3 7{ 8 class Program 9 { 10 static void Main(string[] args) 11 { 12 Console.WriteLine("月(1~12)を入力して下さい"); 13 int m = int.Parse(Console.ReadLine()); 14 string d; 15 16 switch(m) 17 { 18 case 2: 19 d = "28か29"; 20 break; 21 case 4: 22 case 6: 23 case 9: 24 case 11: 25 d = "30"; 26 break; 27 case 1: 28 case 3: 29 case 5: 30 case 7: 31 case 8: 32 case 10: 33 case 12: 34 d = "31"; 35 break; 36 default: 37 Console.WriteLine("適切な値を入力して下さい"); 38 break; 39 } 40 Console.WriteLine("{0}月の長さは{1}日です", m, d); 41 } 42 } 43}
エラーの内容は「未割り当てのローカル変数 'd' が使用されました」というものです。
string d;
という変数の定義では何故ダメなのでしょうか??
default の時に未割り当てです。
回答4件
あなたの回答
tips
プレビュー