簡體   English   中英

如何與System.Type進行比較?

[英]How to compare to System.Type?

DataSet.Tables[0].Columns[0]我們有一個DataType屬性。 現在,我想迭代Columns並根據DataTypeType執行一些操作。 這個怎么做?

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

}

使用typeof運算符:

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

嘗試這個...

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM