0
static void Main(string[] args)
        {
            int countCol= 0;
            string s = "";
            int[,] massiv = null;
            int[,] mas = null;


            do
            {
                Console.WriteLine("Введите элементы строки массива через пробел");
                string str = Console.ReadLine();
                if (str.Trim() != "#")
                    s += str + "!";


            } while

            (str.Trim() != "#");// ошибка


            string[] stroki = s.Split(new char[] { '!' },
                    StringSplitOptions.RemoveEmptyEntries);
                int countRow = stroki.Length;

                for (int i = 0; i < countRow; i++)

            {
                string[] stolbci = stroki[i].Split(new char[] { ' ' },
                    StringSplitOptions.RemoveEmptyEntries);
                if (i == 0)
                {
                    countCol = stolbci.Length;
                    massiv = new int[countRow, countCol];
                }
            }
                   for(int i = 0;i< countRow; i++)
                    {
                        string[] stolbci = stroki[i].Split(new char[] { ' ' },
                            StringSplitOptions.RemoveEmptyEntries);
                if (i == 0)
                {
                    countCol = stolbci.Length;
                    massiv = new int[countRow, countCol];
                }
                            for (int j = 0; j < Math.Min(countCol, stolbci.Length); j++)
                                massiv[i, j] = Convert.ToInt32(stolbci[j]);

                        }

                        for (int i = 0; i < mas.GetLength(0); i++)
                        {
                            for (int j = 0; j < mas.GetLength(1); j++)
                                Console.Write(mas[i,j].ToString().PadLeft(3) + "");
                            Console.WriteLine();
                        }
                    }
  • 2
    Потому что str вложен во внутрь цикла. Вынесите его за цикл do. – EvgeniyZ Apr 29 '19 at 16:53
  • спасибо большое заработало) – Байэл Шаршембиев Apr 29 '19 at 17:05
  • только теперь вся программа гонит, внизу тоже самое выходило на массив mas , я его обьявил в статике вот таким образом - int[,] mas = null; может из за этого? – Байэл Шаршембиев Apr 29 '19 at 17:10
  • Не думаю, что будет "тоже самое". Скорей всего там что то по типу NullReferenceException. Задам вопрос - где вы его инициализируете и заполняете? – EvgeniyZ Apr 29 '19 at 17:54
  • я его вроде не инициализировал походу,честно пока не очень понимаю :-) подскажете может код сразу, буду вам очень благодарен Евгений)))) – Байэл Шаршембиев Apr 29 '19 at 18:00
  • 1
    Почитайте это... https://ru.stackoverflow.com/a/413042/220553 – EvgeniyZ Apr 29 '19 at 18:42

0 Answers0