简体   繁体   中英

How to get the actual type of object

我想获得对象的实际类型,即使我将其转换为其他类型,例如我有一个Integer并将其转换为Object ,有没有办法找出方法呢?

.NET has .GetType() as part of every object. You could use this to do stuff with reflection.

C# also has pattern matching:

if (obj is int intVal)
{
    // use as an integer
}

When you cast or box any value from one type to System.Object , it still under the covers has the same value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM