我想检查方法的参数具有哪种类型,以便给出 我在方法中确定的具有所需类型的变量:
public static Object getFileContent(String filename, Type returntype)
{
if (returntype.GetType().Equals(string))
{
// do something
}
}
这行不通。我能做什么,检查返回类型是否为 string
或 List<string>
?
最佳答案
returntype == typeof(string)
无需调用 GetType
,因为您已经了一个类型。 (GetType
无论如何都不会返回有用的答案,它会返回 typeof(Type))。
关于c# - 检查参数类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15504108/