Multidimensional C # ints list

First of all, I looked through the questions, and I did not find the right thing, maybe it does not exist, but I will give it a shot. I am new to C #, and I'm starting from C ++, got a high school experience.

In C ++, I had it Vector<int> T[];, so I could create a list with a size that he did not know; and do something like that, and not waste space; more precisely

T[0][....];
T[1][...];

1 2 3 4 5
1 2 3 
2 4 1 5
0 0 0 0 0 0

I am trying to do this in C # and it doesn't seem to work; I have tried this so far:

 public class myints
    {
        public int x { get; set; }
    }

  public List<myints[]> T = new List<myints[]>();

  T[i].Add(new myints() { x = i });

I want to be able to add material and then use Count()in forto find out how many elements I have in T[i]. how T[i].size()... is this possible?

program says System.Array does not contain a definition for Add

+4
source share
1

, .

List<List<int>> mainlist = new List<List<int>>();
List<int> counter = new List<int>() { 5, 4, 7, 2 };
int j = 0;

// Fill sublists
foreach(int c in counter)
{
    mainlist.Add(new List<int>(c));
    for(int i = 0; i < c; i++ )
        mainlist[j].Add(i);
    j++;
 }

List<List<int>> mainlist = new List<List<int>>();
mainlist.Add(new List<int>() { 1, 5, 7 });
mainlist.Add(new List<int>() { 0, 2, 4, 6, 8 });
mainlist.Add(new List<int>() { 0, 0, 0 });
+4

Source: https://habr.com/ru/post/1622808/


All Articles