在 Selected dataRow 中,我总共有 200 条数据记录行。现在我需要将200条记录分成20 [10次(for循环)]。所以我使用 take(20)。它将获取前 20 条记录。
我需要删除最后的前20条记录,需要选择另外20条记录。我需要执行10次for循环并获取所有200条记录。
DataRow[] selectedDataRow = dtSMSDetails.Select("description = '" + smsDescription + "'");
if (selectedDataRow.Length > 0)
{
string smsRecordId = "";
string mobileNum = "";
string smsSubject = "";
foreach (DataRow rows in selectedDataRow.Take(20))
{
smsRecordId += rows["activityid"].ToString() + ",";
smsSubject = rows["subject"].ToString();
mobileNum += rows["telephone1"].ToString() + ",";
// Here I need to remove the first 20 (take 20) records from the selected data row and need to loop next 20 records.
}
}
最佳答案
你可以使用Skip()
int startIndex = 0;
for (int i = 0; i < 10; i++)
{
foreach (DataRow rows in selectedDataRow.Skip(startIndex).Take(20))
{
smsRecordId += rows["activityid"].ToString() + ",";
smsSubject = rows["subject"].ToString();
mobileNum += rows["telephone1"].ToString() + ",";
}
startIndex += 20;
}
关于c# - 在 C# 中迭代数据行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41574339/