I\'m completely new to C# and well I would like simple code to create a matrix from user input
E.G.
int [,] matrix1 = new int [2,2]
// now using inpu
I was trying to find a good answer to that question in C#, I searched a lot until a friend helped me to understand how to do it with user input, SO I will leave the answer here maybe it could help anyone
int n = int.Parse(Console.ReadLine()); //the size of the array
int m = n;
int[,] arr = new int[n, m];
string[]lines = new string[n]; // so we could read the input from the user
for (int i = 0; i < n; i++) // here we need to read more than one line
{
lines[i] = Console.ReadLine();
}
for (int i = 0; i < n; i++)
{
string[]num = lines[i].Split(' ');
for (int j = 0; j < m; j++)
{
int z = Convert.ToInt32(num[j]);
arr[i, j] = z;
}
}
for (int i = 0; i < n; i++)
{
Console.WriteLine();
for (int j = 0; j < m; j++)
{
Console.Write(arr[i, j] + " ");
}
}