来源:http://topic.csdn.net/u/20091001/18/41da5177-f8e4-4e8a-b160-4254fd4b19fc.html?49353
public decimal TotalSalaryWithoutRecursion()
{
decimal s = salary;
for (List<Employee> ec = EmployeeCollection; ec != null && ec.Count > 0; ec = SubCollection(ec))
{
foreach (Employee e in ec)
{
s += e.salary;
}
}
return s;
}
private List<Employee> SubCollection(List<Employee> ec)
{
List<Employee> list = new List<Employee>();
foreach (Employee e in ec)
{
if (e.EmployeeCollection != null) list.AddRange(e.EmployeeCollection);
}
return list;
}
在此,for循环的第三个参数它使用了一个方法。而不是通常使用的累加
所以,对for循环的第三项,我的理解的作用是修改第一项的值的内容