Is there a limit of elements that could be stored in a List ? or you can just keeping adding elements untill you are out of memory ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The current implementation of
List<T>usesInt32everywhere – to construct its backing array, for itsCountproperty, as an indexer and for all its internal operations – so there’s a current theoretical maximum ofInt32.MaxValueitems (2^31-1or2147483647).But the .NET framework also has a maximum object size limit of 2GB, so you’ll only get anywhere near the items limit with lists of single-byte items such as
List<byte>orList<bool>.In practice you’ll probably run out of contiguous memory before you hit either of those limits.