转换DataRowCollection到了IEnumerable< T> [英] Convert DataRowCollection to IEnumerable<T>

查看:580
本文介绍了转换DataRowCollection到了IEnumerable< T>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我愿做这样的事情在.NET 3.5。什么是最快的方法是什么?

 的IEnumerable< D​​ataRow的>集合=
    TypedDataSet.TypedTableBase< D​​ataRow的> .Rows为IEnumerable< D​​ataRow的取代;
 

解决方案

假设你正在使用.NET 4.0,它引入了协方差:

  // presumably你的表是从TypedTableBase&LT某种类型的推导; T&GT ;,
//其中T是一个自动生成的类型从DataRow中派生。
IEnumerable的< D​​ataRow的>集合= myTypedTable;
 

借助表类型本身工具的IEnumerable< T>其中,T:DataRow的

否则:

 的IEnumerable< D​​ataRow的>集合= myTypedTable.Cast< D​​ataRow的>();
 

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

IEnumerable<DataRow> collection = 
    TypedDataSet.TypedTableBase<DataRow>.Rows as IEnumerable<DataRow>;

解决方案

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

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

The table type itself implements IEnumerable<T> where T : DataRow.

Otherwise:

IEnumerable<DataRow> collection = myTypedTable.Cast<DataRow>();

这篇关于转换DataRowCollection到了IEnumerable&LT; T&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆