The reason is that by mentioning range
or any extension method of it, you are calling GetEnumerator()
and iterating in some way about it.
For small lists like this, there is not much difference in performance. The thing changes with an enumeration of thousands of records.
Let's get down to the pain. Imagine the following:
var range = Enumerable.Range(0, 100000);
When you assign the variable, you have already created an iterable enumeration per 100000 records. When calling:
var primeiro = range.First();
You are calling GetEnumerator()
again because an enumeration is not a concrete list. So much so that this gives a compile error:
public List<MeuObjeto>()
{
for (int i = 0; i < 10; i++) {
yield return MeuObjeto();
}
}
And this works:
public IEnumerable<MeuObjeto>()
{
for (int i = 0; i < 10; i++) {
yield return MeuObjeto();
}
}
Now imagine the cost of this last function over 100000 records. And that in your case, it runs 2 times.
That's why ReSharper suggests you make the list. He does not know what he's got behind, but he supposes the worst case ever.