Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare to System.Type?

Tags:

c#

types

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 == System.String) {} //error 'string' is a 'type', which is not valid in the given context

}
like image 244
Wodzu Avatar asked Nov 30 '22 05:11

Wodzu


1 Answers

Use the typeof operator:

if (c.DataType == typeof(string))
{
    // ...
}
like image 60
LukeH Avatar answered Dec 01 '22 19:12

LukeH