I just realized that I wrote code that I would expect to be invalid (in terms of syntax), but the compiler accepts.
For brevity, I recreated an example. For type:
private class MyType
{
}
Then I can compare the instance MyTypewith IEnumerable<MyType>:
var myCollection = new List<MyType> { };
var test = new MyType() == (IEnumerable<MyType>)myCollection;
I am surprised that I can compare two objects of different types. Even more interesting (at least interesting to me), if I delete the cast on IEnumerable, I can not compare it. Why is this so? A Listimplements IEnumerable, therefore, assuming that somewhere there is no comparative coefficient of equality (maybe incorrect), why is this not available for Listeither?
source
share