I wonder, what are the differences in collection implementations in .NET .
For instance, I constantly use List<int>
etc to store a list of items. However I just need a container for items, and I guess I don't need all the features that List
have. I just need an container that has put method, and will enable client code to iterate over the container.
Are there any quicker, more lightweight collection implementations that implement IEnumerable<T>
in .NET?
ListDictionary is faster than Hashtable for small collections (10 items or fewer). The Dictionary<TKey,TValue> generic class provides faster lookup than the SortedDictionary<TKey,TValue> generic class.
"In C#, an array is a list" That's not true; an array is not a List , it only implements the IList interface.
A . NET collection is a set of similar type of objects that are grouped together. System. Collections namespace contains specialized classes for storing and accessing the data.
The most lightweight container which implements IEnumerable<T>
is a typed array. It has no Add
method (and therefore does not dynamically resize like a list does) but if you know what number of elements you want up front you can define the array and insert elements at a given position.
var myArray = new int[10];
myArray[0] = 123;
myArray[1] = 234;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With