foreach( B in list<A>) with B inheriting from A [duplicate]

  • Thread starter Vincent Wargnier
  • Start date
V

Vincent Wargnier

Guest
This question already has an answer here:


I would like to know if it is possible to use foreach in c# which focuses only on a specific type of objects which inherit from the type of the list? i tried this but i had a casting error : (B inherites from A)

list<A> myAs;
class B:A{}
foreach (B b in myAs)
{
//do something
}


thank you

Continue reading...
 
Top