2
Reply

Type casting

tom 0

tom 0

Dec 13 2003 3:32 PM
2k
ok, I can not for the life of me figure this one out!! So I have my decendant class: public class STable : Netron.Shape and later on I have a collection of objects. When I try to iterate through it, I get an invalid cast exception. Here is the actual code: foreach( object p_shShape in m_panThePanel.Shapes ) { if( p_shShape.GetType().ToString() == "LazarusWizard.Shapes.STable" ) { Console.Write( ((LazarusWizard.Shapes.STable)p_shShape).Name ); break; } } now, the Console.Write line is reached, and because of the if statement before it I KNOW this object is an STable. I also set a breakpoint to look at it and in the command window I got: p_shShape {LazarusWizard.Shapes.STable} [LazarusWizard.Shapes.STable]: {LazarusWizard.Shapes.STable} Even the m_panThePanel.Shapes collection shows it's an STable: m_panThePanel.Shapes {Length=1} [0]: {LazarusWizard.Shapes.STable} I've also tried things like: STable v_tblTemp = (STable)p_shShape; which gives me the same error.. what in the name of all thats holy is going on here!

Upload Source Code  Select only zip and rar file.
Answers (2)