Reputation: 10037
Is there a limit on how many object a list can hold?
Upvotes: 0
Views: 1064
Reputation: 186
If you look at the count/item/etc property of the generic List (of T); it is an integer.
So i guess Integer.MaxValue (2147483647) is a good guess.
Upvotes: 3
Reputation: 9098
The .Count property of a list is an integer, so it's somewhat limited in this regard.
Upvotes: 2
Reputation: 1401
I believe it is limited to the amount of memory you have. The more you add to the List, the more items are added to the stack until the reference is released and the garbage collector grabs it back.
Upvotes: 0
Reputation: 8007
Please keep in mind that large collections might end up on Large Object Heap. This part of managed memory doesn't get cleaned up as well as Gen0,1,2, so please proceed with caution. Let the runtime select collection sizes based on the data that you actually need to add.
Upvotes: 0
Reputation: 20686
There's an easy way to find out :-)
int count = 0;
while (true)
{
myList.Add(new object());
Console.WriteLine("added " + count++ + " objects");
}
Upvotes: 2
Reputation: 14223
Only those imposed by your physical architecture, available memory etc...
Upvotes: 0