我想做出类似于以下内容的断言:

aMethod.ReturnType == double
aString.GetType() == string


上面的示例显然不能编译,因为doublestring不是Type类型的对象,它们甚至不是合法的C#表达式。

如何表达某种C#类型的Type

最佳答案

使用typeof获取和比较类型。

aMethod.ReturnType == typeof(double)

aString.GetType() == typeof(string)

关于c# - 代表C#中某些类型的对象,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13796642/

10-11 22:31
查看更多