c# casting with is and as

后端 未结 5 983
灰色年华
灰色年华 2021-01-27 13:48

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

5条回答
  •  滥情空心
    2021-01-27 14:21

    Within those if statements you can just cast your object like this:

    var myObjectB = (ClassB)myObject;
    

    or cast it directly:

    ((ClassB)myObject).MethodJustInB();
    

提交回复
热议问题