我想做出类似于以下的断言:
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/