C# 使用For循环遍历DataSet中的所有DataTable

C# 使用For循环遍历DataSet中的所有DataTable,c#,for-loop,foreach,datatable,dataset,C#,For Loop,Foreach,Datatable,Dataset,有人知道如何使用For循环而不是foreach循环遍历数据集中的所有数据表吗 我知道foreach循环可以做到这一点,但是我想用For循环来代替。 例如: foreach (DataTable table in ds.Tables) { } 我想改用For循环。 如果有人能在这方面帮助我,我将不胜感激; DataSet dt = new DataSet(); //Populate dataset here //Iterate throuh datatables inside the

有人知道如何使用
For循环
而不是
foreach
循环遍历数据集中的所有数据表吗

我知道foreach循环可以做到这一点,但是我想用For循环来代替。

例如:

foreach (DataTable table in ds.Tables)
{

}   
我想改用For循环。

如果有人能在这方面帮助我,我将不胜感激;
DataSet  dt = new DataSet();
//Populate dataset here
//Iterate throuh datatables inside the dataset
for(int i=0;i<dt.Tables.Count;i++)
    {
      DataTable temptable = dt.Tables[i]; // this will give you the datatable in each iteration level
        //Do your doce here
    }
//在此处填充数据集 //迭代数据集中的数据表 对于(int i=0;i
DataSet dt=new DataSet();
//在此处填充数据集
//迭代数据集中的数据表

对于(int i=0;i您可以使用
ds.Tables.Count
属性执行此操作:

 for (int i = 0; i < ds.Tables.Count; i++)
 {
     // access your table with indexes:
     Console.WriteLine(ds.Tables[i].ToString());
 }
for(int i=0;i
您可以使用
ds.Tables.Count
属性执行此操作:

 for (int i = 0; i < ds.Tables.Count; i++)
 {
     // access your table with indexes:
     Console.WriteLine(ds.Tables[i].ToString());
 }
for(int i=0;i
数据集dsTemp=新数据集();
for(int tableIndex=0;tableIndex
通过这种方式…

数据集dsTemp=new DataSet();
for(int tableIndex=0;tableIndex

通过这种方式…

我想知道为什么会有一个
DataTableCollection
(它是从
DataSet.Tables
返回的)不实现
IList
但只实现
ICollection
,它没有随机访问,只有
Count
属性。它是一个允许通过索引访问表的属性。我想知道为什么要使用
DataTableCollection
(这是从
DataSet.Tables
返回的)不实现
IList
,但只实现
ICollection
,它没有随机访问,只有
Count
属性。它是一个允许通过索引访问表的属性。