What is the importance of setting a lists capacity at creation?
For example, say I know for sure that my list will only contain n items throughout its lifetime.
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.
Inside of a
List<T>, there is a statically sized collection that holds your items. Once you reach the capacity of that collection, theList<T>re-sizing it which is a performance hit (may or may not be significant to you).By setting the initial capacity, you are avoiding having to perform those re-sizing operations.