我想做出类似于以下内容的断言:
aMethod.ReturnType == double
aString.GetType() == string
上面的示例显然不能编译,因为
double
和string
不是Type
类型的对象,它们甚至不是合法的C#表达式。如何表达某种C#类型的
Type
? 最佳答案
使用typeof获取和比较类型。
aMethod.ReturnType == typeof(double)
aString.GetType() == typeof(string)
关于c# - 代表C#中某些类型的对象,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13796642/