C# 如何获取类实例的类型(不是类的类型,而是类的类型)

C# 如何获取类实例的类型(不是类的类型,而是类的类型),c#,C#,要获取名为myClass的类的类型,我需要执行以下操作 Type myType = (typeof(myClass)) 与其用myClass,不如用InstanceOffCyclass?我怎样才能得到这个类型 假设我有这个 Contact contact = new Contact(); 如果我想知道哪种类型是联系人,我该怎么做 感谢您的帮助您使用contact.GetType;方法GetType在对象类中定义,因此全局可用。使用contact.GetType;方法GetType是在Obje

要获取名为myClass的类的类型,我需要执行以下操作

Type myType = (typeof(myClass))
与其用myClass,不如用InstanceOffCyclass?我怎样才能得到这个类型

假设我有这个

Contact contact = new Contact();
如果我想知道哪种类型是联系人,我该怎么做


感谢您的帮助

您使用contact.GetType;方法GetType在对象类中定义,因此全局可用。

使用contact.GetType;方法GetType是在Object类中定义的,因此全局可用。

如果我没有读错,您可以通过以下方式获取对象的运行时类型:

Contact contact = new Contact();
Type contactType = contact.GetType();

如果我没有看错,您可以通过以下方式获取对象的运行时类型:

Contact contact = new Contact();
Type contactType = contact.GetType();