Last Updated: February 25, 2016
·
499
· aviatrix

Pre-initializing list/dictionaries gives speed improvement

Recently i found out that you gain around 50% speed improvement when adding items to a list/ dictionary if the list/dictionary was initialized before adding the item to it. This is very helpful in the cases where you know how many items the list is going to contain ( or at least approximately )

var list = new List<T>(1000);