Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将数据集数据表转换为IList<;数据表>;类型_C#_Linq - Fatal编程技术网

C# 将数据集数据表转换为IList<;数据表>;类型

C# 将数据集数据表转换为IList<;数据表>;类型,c#,linq,C#,Linq,我有一个包含多个数据表的数据集。现在我想将这些数据表复制到IList对象中 var tables = new[] { DT1, DT2 }; //I want to change this line of code to pull the datatables from the dataset. bool test = Funx(tables); private bool Funx(IList<DataTable> tbls) { ///some operation..

我有一个包含多个数据表的数据集。现在我想将这些数据表复制到IList对象中

var tables = new[] { DT1, DT2 };   //I want to change this line of code to pull the datatables from the dataset.
bool test = Funx(tables);

private bool Funx(IList<DataTable> tbls)
{
   ///some operation..
}
var tables=new[]{DT1,DT2}//我想更改这行代码以从数据集中提取数据表。
布尔检验=Funx(表);
私人布尔芬克斯(IList tbls)
{
///一些手术。。
}
但在我的例子中,数据集可以包含任意数量的数据表。如何使用数据集中的所有datatable准备tables var对象


请建议。

您可以使用
Cast
+
ToList

IList<DataTable> tables = dataSet.Tables.Cast<DataTable>().ToList();
IList tables=dataSet.tables.Cast().ToList();
您需要使用
Enumerable.Cast
,因为(返回者)实现了
IEnumerable
,而不是
IEnumerable
(类是旧的):