Я понятия не имею, почему это происходит или где. Ошибка не предоставляет номера строки. Это ошибка во всей его полноте: < /p>
Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
at HelloWorld.Program.correctString (System.String answer) [0x00000] in :0
at HelloWorld.Program.Main (System.String[] args) [0x001e6] in :0
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
at HelloWorld.Program.correctString (System.String answer) [0x00000] in :0
at HelloWorld.Program.Main (System.String[] args) [0x001e6] in :0
< /code>
ниже мой код. Вплоть до этой ошибки, любая другая ошибка была связана с функцией precomstring () в строке 61. Я не знаю, есть ли это все еще здесь. Ближе, как я могу сказать, нет никакого объявления, который не является созданным. Я с полной потерей. Я даже не могу угадать. < /P>
Любая помощь будет оценена.using System;
using System.Collections.Generic;
using System.Linq;
namespace HelloWorld {
class Program {
static void Main(string[] args) {
string[, ] map = new string[10, 10];
// GLOBAL: Question/answer eadout string
string readout = "";
List < int[] > coords = new List < int[] > {
new int[] {0,0},
new int[] {3,6},
new int[] {8,4}
};
// Commit map of targeted areas to readout string
string[,] display = new string[map.GetLength(0), map.GetLength(1)];
readout += " 0 1 2 3 4 5 6 7 8 9\n";
for (int i = 0; i < map.GetLength(0); i++) {
for (int j = 0; j < map.GetLength(1); j++)
display[i, j] = " - ";
}
foreach(int[] loc in coords)
display[loc[0], loc[1]] = " ░ ";
for (int i = 0; i < map.GetLength(0); i++) {
readout += $"{i} ";
for (int j = 0; j < map.GetLength(1); j++)
readout += display[i, j];
readout += "\n";
}
readout += "\n";
Console.Write(readout);
string typeQuestion = "ENTER AREA TYPE: ";
string typeAnswer = "";
string[] acceptableTypes = new string[] {
"Resistance Base",
"Scrapyard",
"Ruined Hospital",
"Bombed Building",
"Wasteland",
"HK-VTOL",
"HK-TANK",
"Harvester"
};
do {
Console.Clear();
Console.Write(readout);
Console.Write(typeQuestion);
typeAnswer = Console.ReadLine();
typeAnswer = correctString(typeAnswer);
} while (!acceptableTypes.Contains(typeAnswer));
readout += $"{typeQuestion}{typeAnswer}\n";
}
// CORRECT AREA TYPE STRING FUNCTION
static string correctString(string answer) {
if (answer.ToUpper() == "HK-TANK" || answer.ToUpper() == "HK-VTOL")
return answer.ToUpper();
string newString = "";
for (int i = 0; i < answer.Length; i++) {
if (i == 0) {
newString += answer.ToString().ToUpper();
} else {
newString += answer.ToString().ToLower();
}
}
return newString;
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... -an-object
C# Проблема: ссылка на объект не установлен на экземпляр объекта ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
EF Core 7 Ошибка миграции: ссылка на объект не установлен на экземпляр объекта
Anonymous » » в форуме C# - 0 Ответы
- 3 Просмотры
-
Последнее сообщение Anonymous
-