tags:

views:

178

answers:

4

Hello Experts,

I want to know how many values i can assign to List? For example

List<string> Item= runtime data

Data is not fixed.it may be 10000 or more than 1000000.I have Googled but not getting an exact answer.Please help me to solve the issue.

Thanks

+2  A: 

Maybe it depends on the memory available on your PC. Why don't you try it?

Ahmad Farid
+16  A: 

The maximum number of elements that can be stored in the current implementation of List<T> is, theoretically, Int32.MaxValue - just over 2 billion.

In the current Microsoft implementation of the CLR there's a 2GB maximum object size limit. (It's possible that other implementations, for example Mono, don't have this restriction.)

Your particular list contains strings, which are reference types. The size of a reference will be 4 or 8 bytes, depending on whether you're running on a 32-bit or 64-bit system. This means that the practical limit to the number of strings you could store will be roughly 536 million on 32-bit or 268 million on 64-bit.

In practice, you'll most likely run out of allocable memory before you reach those limits, especially if you're running on a 32-bit system.

LukeH
In addition to the fixed upper limit, creating and releasing large arrays repeatedly can lead to inconsistent allocation where even more reasonable allocations (on the order of a few 100 MB) can cause OutOfMemoryException, even though the memory is actually available. If you have to deal with very large collections, this will impact your design.
Dan Bryant
+3  A: 

2147483647 because all functions off List are using int.

Source from mscorlib:

private T[] _items;
private int _size;

public T this[int index]
{
  get
    {
      //...
    }
}
Floyd
+1  A: 

list.Count() property is int32, so it must be the maxium limit of int32 but how your list performs over this limit is a nice observation.

if you do some list manupulation operations, it would be linier in theory.

i would say if your are having very large number of items thnink about the Parallel Collections in .net 4.0 this would make your list operations more responsive.

saurabh