Answer the question
In order to leave comments, you need to log in
Filtering with OfType?
Why doesn't this example output anything?
class Program
{
static void Main(string[] args)
{
IEnumerable<IEnumerable<A>> a = new List<IEnumerable<A>> { new List<A> { new B(), new B() }, new List<A> { new C(), new C() } };
var b = a.OfType<IEnumerable<B>>();
var c = a.OfType<IEnumerable<C>>();
foreach (var collections in b)
foreach (var items in collections)
items.foo();
foreach (var collections in c)
foreach (var items in collections)
items.foo();
}
}
abstract class A
{
public abstract void foo();
}
class B : A
{
public override void foo() => Console.WriteLine("B");
}
class C : A
{
public override void foo() => Console.WriteLine("C");
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question