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
I prefer to cast with as and then check for null, this way you can skip the is check. Also, you do not need the elvis operator ?. because you know the object is not null.
var myObjectA = myObject as ClassA;
var myObjectB = myObject as ClassB;
if (myObjectA != null)
{
myObjectA.MethodJustInA();
}
else if (myObjectB != null)
{
myObjectB.MethodJustInB();
myObjectB.OtherMethodJustInB();
}