繁体   English   中英

如何与System.Type进行比较?

[英]How to compare to System.Type?

DataSet.Tables[0].Columns[0]我们有一个DataType属性。 现在,我想迭代Columns并根据DataTypeType执行一些操作。 这个怎么做?

foreach(var c in DataSet.Tables[0].Columns)
{
  if (c.DataType == System.String) {} //error 'string' is a 'type', which is not valid in the given context

}

使用typeof运算符:

if (c.DataType == typeof(string))
{
    // ...
}

尝试这个...

if (c.DataType == typeof(string)) {}
if (c.DataType == typeof(string))
{
    // code
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM