Using a list of 10 million random int
s (same seed each time, average of 10 repetitions):
listCopy.Sort(Comparer
ILSpy decompiles thus:
public override int Compare(T x, T y)
{
if (x != null)
{
if (y != null)
{
return x.CompareTo(y);
}
return 1;
}
else
{
if (y != null)
{
return -1;
}
return 0;
}
}
The null checks will always evaluate as true
for a value type, so they will be optimized away; the end result will be
public override int Compare(T x, T y)
{
return x.CompareTo(y);
}