C#, Is it possible to recast an object and access methods and properties without creating new object variable?
For example:
foreach (object o in collection)
{
if (o is MyType)
{
(MyType)o.MyProperty = x
}
}
Currently, I have to re-cast o to another variable of MyType [ex: MyType m = (MyType)o ] in order to access methods or properties of MyType. It seems wasteful, so I'm wondering if I'm missing some mechanic that will allow me to skip the declaration of a new object variable.