Does List<>.IndexOf compare by reference or value?

.net, c#

Solution

From MSDN:

This method determines equality using the default equality comparer EqualityComparer<T>.Default for T, the type of values in the list.

The Default property checks whether type T implements the System.IEquatable<T> generic interface and if so returns an EqualityComparer<T> that uses that implementation. Otherwise it returns an EqualityComparer<T> that uses the overrides of Object.Equals and Object.GetHashCode provided by T.

It seems like it uses the Equals method, unless the stored class implements the IEquatable<T> interface.

Problem

``` List<tinyClass> ids = new List<tinyClass(); ids.Add(new tinyClass(1, 2)); bool b = ids.IndexOf(new tinyClass(1, 2)) >= 0; //true or false? ``` If it compares by value, it should return true; if by reference, it will return false. If it compares by reference, and I make tinyClass a struct - will that make a difference?

Original source