C# 'is' operator Clarification

前端 未结 6 1972
半阙折子戏
半阙折子戏 2021-01-17 21:11

Does the is operator indicate whether or not an object is an instance of a certain class, or only if it can be casted to that

6条回答
  •  感动是毒
    2021-01-17 21:23

    is indicate if the object can be casted to a class or interface.

    If you have a BaseClass and a SubClass then:

    var obj = new SubClass();
    

    obj is SubClass returns true;

    obj is BaseClass also returns true;

提交回复
热议问题