Convert DataRowCollection to IEnumerable

后端 未结 4 916
孤城傲影
孤城傲影 2020-12-05 16:39

I would like to do something like this in .NET 3.5. What\'s the quickest way?

IEnumerable collection = 
    TypedDataSet.TypedTableBase

        
4条回答
  •  借酒劲吻你
    2020-12-05 17:27

    Assuming you're using .NET 4.0, which introduces covariance:

    // Presumably your table is of some type deriving from TypedTableBase,
    // where T is an auto-generated type deriving from DataRow.
    IEnumerable collection = myTypedTable;
    

    The table type itself implements IEnumerable where T : DataRow.

    Otherwise:

    IEnumerable collection = myTypedTable.Cast();
    

提交回复
热议问题