An IEnumerable<T>
is not neccessarily a real object. IEnumerable<T>
guarantees that you can enumerate through it's states. In simple cases you have a container class like a List<T>
that is already materialized. Then you could compare both Lists' addresses. However, your IEnumerable<T>
might also point to a sequence of commands, that will be executed once you enumerate. Basically a state machine:
public IEnumerable<int> GetInts()
{
yield return 10;
yield return 20;
yield return 30;
}
If you save this in a variable, you don't have a comparable object (everything is an object, so you do... but it's not meaningful):
var x = GetInts();
Your comparison only works for materialized ( .ToList()
or .ToArray()
) IEnumerables, because those state machines have been evaluated and their results been saved to a collection. So yes, the library actually makes sense, if you know you have materialized IEnumerables, you will need to make this knowledge public by casting them to Object and calling the desired function on this object "manually".