Dynamically store matrix values ​​in C #

I am trying to create an application in C # .net

Here I have two one-dimensional arrays of the same size. For example, I have matrices M and N, as in the structure below:

M[0] M[1] M[2] M[3] M[4] N[0] N[1] N[2] N[3] N[4] 

Here I assigned my values ​​M [0] .... and N [0] ...... to them, to get a matrix like:

  5 6 4 8 4 8 7 2 

Note I made these values ​​to generate dynamically. I succeeded before this step.

But I like to store the values ​​in another array (maybe an uneven array or something else) in a 2x2 matrix in this format:

  A[0] A[1] B[0] 5 4 (this is the values of M[0] and N[0]) B[1] 6 4 (this is the values of M[1] and N[0]) .............. B[4] 5 8 (this is the values of M[0] and N[1]) 

When the first line N [0] is completed, it should continue the next line. I just need to implement this in C # ??

+6
source share
3 answers

To save dynamically you need to know the basics of 2d and 3d

See here

2-D arrays: dotnetperls.com/2d-array

multidimensional arrays: msdn.microsoft.com/en-us/library/2yd9wwz4 (v = vs .71) .aspx

+2
source

You cannot assign values ​​to arrays later. I would recommend using List<List<int>> , here is an example:

 List<List<int>> val = new List<List<int>>(); List<int> M = new List<int>() { 1, 2, 3, 4, 5 }; List<int> N = new List<int>() { 5, 4, 3, 2, 1 }; foreach (int m in M) { foreach (int n in N) { val.Add(new List<int> { m, n }); } } 
+1
source

stackoverflow.com/questions/594853/dynamic-array-in-c-sharp Checkout above. Or check out the source below.

msdn.microsoft.com/en-us/library/system.collections.arraylist.aspx

+1
source

All Articles