什么是C#等同于Java的的instanceof和isInstance()? [英] What is the C# equivalent to Java's instanceof and isInstance()?

查看:893
本文介绍了什么是C#等同于Java的的instanceof和isInstance()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道的instanceof ,而是反射 isInstance什么()方法


解决方案

 布尔结果= obj.GetType() .IsAssignableFrom(otherObj.GetType()); 


I know of is and as for instanceof, but what about the reflective isInstance() method?

解决方案

bool result = obj.GetType().IsAssignableFrom(otherObj.GetType());

这篇关于什么是C#等同于Java的的instanceof和isInstance()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆