I need some help. It is pretty easy. I have this piece of code, and I would like to discuss if it is correct, or if you suggest a better way to do it. I have an idea about the a
If you're using it this way, you only need to cast it ones:
var myObjectA = (myObject as ClassA);
if (myObjectA != null)
{
myObjectA.MethodJustInA();
}
else
{
var myObjectB = (myObject as ClassB);
if (myObjectB != null)
{
myObjectB.MethodJustInB();
}
}
And in C# 7.0 you can do:
if (myObject is ClassA myObjectA)
myObjectA.MethodJustInA();
else
if (myObject is ClassB myObjectB)
myObjectB.MethodJustInB();