【发布时间】:2014-01-29 09:56:19
【问题描述】:
我做了一个这样的循环:
int total;
total = ((toVal - fromVal) + 1) * 2;
RadProgressContext progress = RadProgressContext.Current;
progress.Speed = "N/A";
finYear = fromVal;
for (int i = 0; i < total; i++)
{
decimal ratio = (i * 100 / total);
progress.PrimaryTotal = total;
progress.PrimaryValue = total;
progress.PrimaryPercent = 100;
progress.SecondaryTotal = 100; // total;
progress.SecondaryValue = ratio;//i ;
progress.SecondaryPercent = ratio; //i;
progress.CurrentOperationText = "Step " + i.ToString();
if (!Response.IsClientConnected)
{
//Cancel button was clicked or the browser was closed, so stop processing
break;
}
progress.TimeEstimated = (total - i) * 100;
//Stall the current thread for 0.1 seconds
System.Threading.Thread.Sleep(100);
}
现在我想根据toVal & fromVal 运行一个特定的方法
在前一个循环中,但循环次数不同
我想像这样循环运行它:
for (fromVal; fromVal < toVal ; fromVal++)
{
PrepareNewEmployees(calcYear, fromVal);
}
例如:
fromVal = 2014
toVal = 2015
所以我想跑两次而不是四次!像这样:
PrepareNewEmployees(calcYear, 2014);
PrepareNewEmployees(calcYear, 2015);
但在上一个循环中for (int i = 0; i < total; i++)
【问题讨论】:
-
在计算
total = ((toVal - fromVal) + 1) * 2时为什么要做* 2? -
那么
for (fromVal; fromVal < toVal ; fromVal++)有什么问题? -
@RoyDictus :因为某些方法在(一月,七月)的财政年度运行两次,例如如果
toVal = 2015 , fromVal = 2014然后我有7-2014 1-2015 7-2015 1-2016 -
我不确定我是否理解 - 为什么不能在第一个循环中嵌套另一个循环?
-
我真的不明白你的意图。能不能换个说法解释一下?
标签: c# asp.net linq loops for-loop