I congratulate everyone on the coming !!! I study C # and now I decided to write a simple console game, please tell me that it’s not right in my code, that is, it doesn’t compile, and if it doesn’t go through the switch branch, for example, I enter the coordinates 0.0 I press Enter and nothing happens :

using System; using System.Collections.Generic; namespace AppGame { class MainClass { public static void Main(string[] args) { string[,] text = new string[2, 2]; do { text[0, 0] = "Привет Мир!!! Я делаю консольную Игру поддержите проект интеллектуально!"; text[0, 1] = "Hello, World!!!"; text[1, 0] = "В этой комнате лежит книга 20 000 лье под водой!"; text[1, 1] = "Лежит ключ от двери из этого дома!"; Console.WriteLine("Здесь четыре комнаты 1 на 1 при раскладе 2 на 2 это стены"); text[2, 2] = Convert.ToString(ConsoleKey.Enter); text[2, 2] = Convert.ToString(Console.ReadLine()); switch (text[2, 2]) { case "0, 0": { Console.WriteLine(text[0, 0]); break; } case "0,1": { Console.WriteLine(text[0, 1]); break; } case "1,0": { Console.WriteLine(text[1, 0]); break; } case "1,1": { Console.WriteLine(text[1, 1]); break; } default: { Console.WriteLine("\nнет такой локации или команды"); break; } case "чисто": { Console.Clear(); break; } } Console.ReadKey(); } while (true); } } } 
  • You know, in VisualStudio there is such a useful thing - a debugger. - Igor
  • Igor I do not quite understand the debugger at the level of a novice C # programmer, if I say, I don’t understand it at all, tell me what the error is please - Sergey

1 answer 1

The array indices in C # vary from zero to the length of the array minus one.

 string[,] text = new string[2, 2]; // матрица строк 2х2 ... text[2, 2] = ...; // пытается присвоить значение третьему элементу в третьей строке матрицы, вылезает за границу массива 
  • And what to do with the third element in the third row of the matrix - Sergey
  • @ Sergey Why do you need a matrix at all? Get five string variables. - Igor
  • Well try - Sergey