0

This question must've been asked before, I'm pretty sure I'm missing something obvious, but I'm struggling to find an answer to this.

Say we have an abstract class called Base, and we have a class that inherits from it, called Derived.

Considering that, I don't understand why the following condition in the if clause doesn't evaluate to true?!

ISomeInterface<Derived> foo = ...;
if (foo is ISomeInterface<Base>) // => false - but why?!
{
    // Blah blah...
}

While this would:

Derived foo = ...;
if (foo is Base) // true
{
    // Blah blah...
}

I'd appreciate it if you point me in the right direction.

Arad Alvand
  • 8,607
  • 10
  • 51
  • 71
  • 2
    An `IList` shouldn't be treated as an `IList` because it's still inherently a container of oranges but an `IList` can `.Add(new Apple())`. – Damien_The_Unbeliever Oct 18 '21 at 07:43
  • 2
    Your question has a false premise. It _would_ be true if `ISomeInterface` was declared as `interface ISomeInterface`. `IEnumerable` _is_ a kind of `IEnumerable`. – Sweeper Oct 18 '21 at 07:43

0 Answers0