Dynamic matrix in C#

Asked

Viewed 151 times

1

What would be the best way to create a dynamic square matrix ?

An array that increases row and column as elements appear to be inserted into the matrix

I found some comments on the internet saying that the best way to do this would be to create lists

List<List<int>> matriz= new List<List<int>>();

I’m having trouble understanding how to fill the matrix.

  • Estou com dificuldades para entender.? What the difficulties! what you did apparently gives to make an array of any size (row and columns) only that control and via code. I was in doubt of a scenario?

  • 1

    @Virgilionovic, sorry for the lack of information, my difficulty is in filling this matrix

  • 1

    I wanted to help you, but there’s no way. but, I will leave a link https://dotnetfiddle.net/HRkGQ is a 4 x 4 matrix but, I know it is! and I know I programmed so, this list can increase both for column and row ... the control is done via code

  • 1

    Thank you so much anyway

  • If you doubt me, ask me there

1 answer

0

Use Tuple:

Tuple<int, int, int, int> tuple = new Tuple<int, int, int, int>( 1, 2, 3, 4);
List<Tuple<int, int, int, int>> matriz = new List<Tuple<int, int, int, int>>();
matriz.Add(tuple);
  • Truplas can be written as List<(int, int, int, int)> also.

  • 1

    This does not allow growing rows and columns.

Browser other questions tagged

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