将 DataRowCollection 转换为 IEnumerable<T>; [英] Convert DataRowCollection to IEnumerable&lt;T&gt;

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

问题描述

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

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>;

推荐答案

假设您使用的是 .NET 4.0,它引入了协方差:

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;

表类型本身实现了IEnumerable其中 T : DataRow.

否则:

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

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

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