开发者

How to compare to System.Type?

开发者 https://www.devze.com 2023-01-08 01:14 出处:网络
In DataSet.Tables[0].Columns[0] we have a DataType property. Now, I would like to iterate over Columns and perform some action depending on the Type in DataType. How to do this?

In DataSet.Tables[0].Columns[0] we have a DataType property. Now, I would like to iterate over Columns and perform some action depending on the Type in DataType. How to do this?

foreach(var c in DataSet.Tables[0].Columns)
{
  if (c.DataType == Sys开发者_高级运维tem.String) {} //error 'string' is a 'type', which is not valid in the given context

}


Use the typeof operator:

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


Try this...

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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号