Category Archives: Playing around with List

Playing around with List<T>, part five: finding elements

This time I’ll try to examine how are all search-related methods in List<T> implemented. Here is quite long list of all these methods:

public bool Exists(Predicate<t> match)
public T Find(Predicate</t><t> match)
public List</t><t> FindAll(Predicate</t><t> match)
public int FindIndex(Predicate</t><t> match)
public int FindIndex(int startIndex, Predicate</t><t> match)
public int FindIndex(int startIndex, int count, Predicate</t><t> match)
public T FindLast(Predicate</t><t> match)
public int FindLastIndex(Predicate</t><t> match)
public int FindLastIndex(int startIndex, Predicate</t><t> match)
public int FindLastIndex(int startIndex, int count, Predicate</t><t> match)
public int IndexOf(T item)
public int IndexOf(T item, int index)
public int IndexOf(T item, int index, int count)
public int LastIndexOf(T item)
public int LastIndexOf(T item, int index)
public int LastIndexOf(T item, int index, int count)</t>

Continue reading Playing around with List<T>, part five: finding elements

Playing around with List<T>, part two: IEnumerable and IEnumerable<T> implementation

After a while I finally found some time to write another post about List<T> internals. This time it’s all about enumeration, so I’m going to go through both non-generic IEnumerable and generic IEnumerable<T> interfaces implementation.

It may be a little bit surprising, but there are actually three GetEnumerator() methods within List<T> class. That’s because both IEnumerable.GetEnumerator() and IEnumerable<T>.GetEnumerator() methods are implemented explicitly (and there is another one, not connected to any of the interfaces):
Continue reading Playing around with List<T>, part two: IEnumerable and IEnumerable<T> implementation

Playing around with List<T>, part one: Constructors

List<T> is one of the most commonly used types from .NET Framework Base Class Library. Although it is used so often not everyone is really familiar with how the class works internally. Almost everyone knows that List<T> uses T[] array internally to store the items. But for most people that’s the only internal detail they know. In next few blog post I’ll try to step through List<T> source code and point some interesting implementation details that every .NET developer should be aware of.

Starting from the basics, I’d like to dive deep into List<T> class constructors first. There are three instance constructors available:
Continue reading Playing around with List<T>, part one: Constructors