How to compare with System.Type?

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

 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 } 
+4
source share
3 answers

Use the typeof operator:

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

Try it...

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

Source: https://habr.com/ru/post/1316423/


All Articles