Multi-dimensional matrix declaration

Asked

Viewed 65 times

1

I’m trying to create a multidimensional matrix, but I don’t know what I’m doing wrong:

var players = new string[,]{ { { { "Armando", "P" }, { "Dave", "S" } }, { { "Richard", "R" }, { "Michael", "S" } } }, { { { "Allen", "S" }, { "Omer", "P" } }, { { "David E.", "R" }, { "Richard X.", "P" } } } };

I’m getting the following error:

Como deve sair no final quando a matriz já está montada

I want to create an object like this below:

inserir a descrição da imagem aqui

  • How many dimensions should the matrix have?

  • @Maniero put an example of what I would like to create

1 answer

2


It doesn’t seem to make sense, but it’s riding a array 4-dimensional, so you have to declare this way. I also made for two (the amount declared in the code), but the result presented seems to want 4 even, although I think at most 3 would solve, so I did for this amount too.

public class Program {
    public static void Main() {
        var players = new string[,,,] { { { { "Armando", "P" }, { "Dave", "S" } }, { { "Richard", "R" }, { "Michael", "S" } } }, { { { "Allen", "S" }, { "Omer", "P" } }, { { "David E.", "R" }, { "Richard X.", "P" } } } };
        var players3 = new string[,,] { { { "Armando", "P" }, { "Dave", "S" } }, { { "Richard", "R" }, { "Michael", "S" } }, { { "Allen", "S" }, { "Omer", "P" } }, { { "David E.", "R" }, { "Richard X.", "P" } } };
        var players2 = new string[,] { { "Armando", "P" }, { "Dave", "S" }, { "Richard", "R" }, { "Michael", "S" }, { "Allen", "S" }, { "Omer", "P" }, { "David E.", "R" }, { "Richard X.", "P" } };
    }
}

Behold working in the ideone. And in the .NET Fiddle. Also put on the Github for future reference.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.