如何向这个 foreach 循环添加一个计数器?
How can I add a counter to this foreach loop?
如何向此代码添加计数器?
foreach(DataSet1.Save_PropertyRow r in DT)
{
var testProperty = CreateTestAOProperty(r.ADDRESS, r.Adjustments...);
var savePropertyResult = _Client.SaveProperty(credentials, testProperty);
Console.WriteLine("Save Property result: \"{0}\" with message \"{1}\"", savePropertyResult.Status, savePropertyResult.Message);
LogMessageToFile(CaseID, "Property Results Saved to log");
Console.ReadLine();
在循环外定义一个整数,并在循环内递增它。
int count = 0;
foreach(value in array)
{
Console.WriteLine("Current count: {0}", count);
//Do your thing.
count++;
}
或
使用 for 循环而不是 foreach,它有一个计数:
for(int i = 0; i < array.length; i++)
{
var item = array[i];
Console.WriteLine("Current count: {0}", i + 1);
//Do your thing.
}
如何向此代码添加计数器?
foreach(DataSet1.Save_PropertyRow r in DT)
{
var testProperty = CreateTestAOProperty(r.ADDRESS, r.Adjustments...);
var savePropertyResult = _Client.SaveProperty(credentials, testProperty);
Console.WriteLine("Save Property result: \"{0}\" with message \"{1}\"", savePropertyResult.Status, savePropertyResult.Message);
LogMessageToFile(CaseID, "Property Results Saved to log");
Console.ReadLine();
在循环外定义一个整数,并在循环内递增它。
int count = 0;
foreach(value in array)
{
Console.WriteLine("Current count: {0}", count);
//Do your thing.
count++;
}
或
使用 for 循环而不是 foreach,它有一个计数:
for(int i = 0; i < array.length; i++)
{
var item = array[i];
Console.WriteLine("Current count: {0}", i + 1);
//Do your thing.
}