前提・実現したいこと
初心者なので色々アドバスください。
コレクション型のDictionaryを使い配列作っています。
Dictionaryの配列を実装中に以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
1、System.NullReferenceException: Object reference not set to an instance of an object 2、NullReferenceException: Object reference not set to an instance of an object
該当のソースコード
C#
1 string[] KeyTable = new string[4] { "UP", "DOWN", "RIGHT", "LEFT" }; 2 int[,] ValueTable = new int[4, 4] { 3 {0,0,0,0}, 4 { 0,1,2,0}, 5 { 0,3,2,0}, 6 { 0,0,0,0}, 7 }; 8 9 Dictionary<string, int>[] move = new Dictionary<string, int>[4]; 10 //値の数 11 for (int i = 0; i < 4; i++) 12 { 13 //キーの数 14 for (int j = 0; j < 4; j++) 15 { 16 //Dictionaryにキーと値を入れる 17 move[i].Add(KeyTable[i], ValueTable[i, j]); 18 19 } 20 } 21
試したこと
moveの要素の削除
補足情報(FW/ツールのバージョンなど)
エラーの場所は、for文内のイカの場所です。
//Dictionaryにキーと値を入れる
move[i].Add(KeyTable[i], ValueTable[i, j]);
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/24 18:09 編集
2018/08/24 18:11
2018/08/25 05:22