c# - 检查参数类型

标签 c#

我想检查方法的参数具有哪种类型,以便给出 我在方法中确定的具有所需类型的变量:

public static Object getFileContent(String filename, Type returntype)
{
     if (returntype.GetType().Equals(string))
     {
       // do something
     }
}

这行不通。我能做什么,检查返回类型是否为 stringList<string>

最佳答案

returntype == typeof(string)

无需调用 GetType,因为您已经了一个类型。 (GetType 无论如何都不会返回有用的答案,它会返回 typeof(Type))。

关于c# - 检查参数类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15504108/

相关文章:

c# windows service process.start 收藏

c# - 声明多维数组

c# - WPF Prism 中的单元测试确认

c# - 在 WPF DataGrid 中删除行和更改数据时遇到问题(使用 MySQL)

c# - 有什么简单的方法可以根据 C# 中的键对 NameValueCollection 进行排序?

javascript - Sweet Alert函数在js脚本调用时不会触发

c# - 将剧院座位保存到数据库的最快方法

c# - AdSense 和 Webstats 等系统如何运作?

c# - 消息框显示没有空格?

c# - 用 html 值替换 xml 标签