Answer the question
In order to leave comments, you need to log in
How to create an array of lists through C# classes?
Good afternoon. As planned, I have an array (map), each cell can contain many values \u200b\u200bwith which I will need to work. Decided to implement through classes.
class map
{
public Coordinates[,] Coor;
//параметры карты
public int n;
public int m;
public map(int n) { this.Coor = new Coordinates[n, n];
this.n = n; this.m = n;
}
public map(int n, int m) { this.Coor = new Coordinates[n, m]; this.n = n; this.m = m; }
}
class Coordinates
{
public List<int> Type=new List<int>();
}
map Map = new map(2);
Map.Coor[1,1].Type.Add(1);
Map.Coor[1,1].Type.Add(2);
Map.Coor[0, 0].Type.Add(2);
Console.WriteLine("count "+Map.Coor[1, 1].Type.Count);
Answer the question
In order to leave comments, you need to log in
You have created an empty array Coor
for the elements. But you don't have the elements themselves. It is necessary new Coordinates
to do on all array, each element. And learn how to debug your code.
How to look for the causes of such similar errors:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question