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
}
精彩评论