提问人:NiclasNilsson 提问时间:9/8/2023 最后编辑:Ian KempNiclasNilsson 更新时间:9/8/2023 访问量:32
需要 true While () 和 foreach()
Need to go true While () and foreach()
问:
如果一个值小于或等于一个数字,我试图去 foreach。 我之前有一段时间,但它只运行了 1 次,然后 foreach 但每次都需要检查 我怎样才能做到这一点
这是我现在尝试过的代码:
While (i <= batchSize)
{
foreach (DataRow dtRow in dt1.Rows)
{
var number = dtRow.ItemArray[0];
var surname = dtRow.ItemArray[1];
var forename = dtRow.ItemArray[2];
var emailAddress = dtRow.ItemArray[3];
string taxidentifier = (string)dtRow.ItemArray[4];
//string taxidentifier = "2211221143";
if (Personnummer.Valid(taxidentifier))
{
body += "{\"itemId\": \"" + number + "\",\"subjectId\": \"" + taxidentifier + "\"},";
batch = i++;
}
}
答:
2赞
Hexagon
9/8/2023
#1
语句条件需要在语句的每次迭代中检查?while
foreach
由于只运行一次,因此只需将语句替换为开头具有相同条件的语句即可:while
while
if
foreach
foreach (DataRow dtRow in dt1.Rows) {
if (i > batchSize)
break;
// Do what you have to;
}
评论