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();
}
}
Asked
Active
Viewed 271 times
0
strвложен во внутрь цикла. Вынесите его за циклdo. – EvgeniyZ Apr 29 '19 at 16:53NullReferenceException. Задам вопрос - где вы его инициализируете и заполняете? – EvgeniyZ Apr 29 '19 at 17:54