I'm new to C#, so this question might be an easy one. However I did not find any solution yet.
Description of the problem:
I want to create and empty array [4] of lists [length not know]. Later on I will read out four different channels and fill the list with objects created beforehand.
What I did so far
class objChannel
{
private int channel;
public objChannel(int inputChannel)
{
channel = inputChannel;
}
public int Channel {get {return channel;}}
}
List<objChannel>[] listChannel = new List<objChannel>[4];
listChannel[1].Add(objChannel(1));
This does not work because of an null error.
Right now I have a work around like this:
List<objChannel>[] listChannel = {new List<objChannel> { new objChannel(1) },
new List<objChannel> { new objChannel(2) },
new List<objChannel> { new objChannel(3) },
new List<objChannel> { new objChannel(4) }};
However, this will give me non-empty list.