代码之家  ›  专栏  ›  技术社区  ›  Wodzu

如何与系统类型进行比较?

  •  4
  • Wodzu  · 技术社区  · 15 年前

    DataSet.Tables[0].Columns[0] 我们有一个 DataType 财产。现在,我想重复一下 Columns 并根据情况采取行动 Type 在里面 . 怎么做?

    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
    
    }
    
    3 回复  |  直到 15 年前
        1
  •  14
  •   LukeH    15 年前

    使用 typeof 操作员:

    if (c.DataType == typeof(string))
    {
        // ...
    }
    
        2
  •  4
  •   robyaw    15 年前

    试试这个。。。

    if (c.DataType == typeof(string)) {}
        3
  •  4
  •   Damian Leszczyński - Vash    15 年前
    if (c.DataType == typeof(string))
    {
        // code
    }