开发者

How to compare to System.Type?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜