0
I’m making a simple matrix code in C# to display string values, only it appears CS0847 Error: Matrix initializer of length "3" on line 9 and did not understand what it means.
using System;
namespace TesteMatriz1
{
class Program
{
static void Main(string[] args)
{
string[,] lista = new string[3, 3] { { "Dante", "Sparda" }, { "Vergil", "Sparda" }, { "Nero", "Sparda" } };
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
Console.WriteLine($"Nome: {lista[i, j]}");
}
}
Console.ReadKey();
}
}
}
Why these two are s together and why you replaced the string list with var list?
– user141036
'Cause I like to write less code when it makes sense.
– Maniero
How can I replace this gambit of
Nome ({i},{j}): {lista[i, j]}
to showNome (0,0): Dante, Nome(0,1): Nero
, or the way I did is right?– user141036
If that’s what you want it’s right.
– Maniero
How do I join some elements of the matrix in the same line: for example: Dante Sparda is one person and not two, in one line appears Dante and in the other Sparda.
– user141036
Depends exactly how do you want, but that’s another question, try asking, if it doesn’t work open a new question.
– Maniero
I get it, I’ll try to do.
– user141036