Reputation: 4273
How can I set the capacity of new List<List<Brick>>();
, to be (10,12) ?
Something like this does not compile: List<new List<Brick>(10)>(12);
and I did not find anything related to this when I searched.
Upvotes: 0
Views: 545
Reputation: 6102
List<List<Brick>> bricks = new List<List<Brick>>{
new List<Brick>(12),
new List<Brick>(12),
new List<Brick>(12),
// ...
new List<Brick>(12),
};
Upvotes: 1
Reputation: 13171
You can set the capacity of a list when you construct it.
First you would create your outer list with its capacity of 12 by specifying the capacity in its constructor.
Then, loop through and add 12 lists of capacity 10 to your outer list.
If your outer list may contain some number of lists < 12, then you just have to make sure each time you add a new inner list you specify its capacity too.
Edit: the declaration for your outer list should be:
List<List<Brick>> outer = new List<List<Brick>>(12);
Upvotes: 2