I have a base class and a derived class, which inherits from it. These have a method that adds them to a Hashtable. I am looping through the collection using a foreach, as such:
foreach ( BaseClass bc in myHashtable )
this will perform the DoSomething method for both the base and derived classes. Is there an efficient way to extract just the derived classes or do I have to switch ( bc.GetType() )? I have tried:
foreach ( DerivedClass dc in myHashtable )
but, if it hits a BaseClass object, I am told that it cannot cast from type BaseClass to DerivedClass.
Is there a fast alternative?