C# 在运行时c提取for循环计数的值#
我的困境是:C# 在运行时c提取for循环计数的值#,c#,tcpclient,C#,Tcpclient,我的困境是: public void checkCountProgress(int countProgress, int totalDataSize){ //work done here} public void func1(int passVar) { for(int = 0; i<= 2000; i+=64){ //do work checkCountProgress(i, 2000); } } public void checkCount
public void checkCountProgress(int countProgress, int totalDataSize){ //work done here}
public void func1(int passVar)
{
for(int = 0; i<= 2000; i+=64){
//do work
checkCountProgress(i, 2000);
}
}
public void checkCountProgress(int countProgress,int totalDataSize){//work done here}
公共无效函数1(int-passVar)
{
对于(int=0;i您的意思是使用设置来存储循环停止时的值?
如果是这样,下面是一个如何使用它们的示例
在项目的属性中,在设置选项卡中添加所需值类型的新设置,并将范围设置为用户。在我的示例中,我创建了一个名为ValueToResume的类型,初始值为0
static void Main(string[] args)
{
int initialLoopValue = Properties.Settings.Default.ValueToResume;
for (int i = initialLoopValue; i <= 2000; i += 64)
{
//do work
checkCountProgress(i, 2000);
}
Properties.Settings.Default.Reset(); //Loop was completed, we can reset the setting to 0
}
public static void checkCountProgress(int countProgress, int totalDataSize)
{
if (countProgress > 600)
{
Properties.Settings.Default.ValueToResume = countProgress;
Properties.Settings.Default.Save();
Environment.Exit(0); //force application exit
}
}
}
static void Main(字符串[]args)
{
int initialLoopValue=Properties.Settings.Default.ValueToResume;
for(int i=初始循环值;i 600)
{
Properties.Settings.Default.ValueToResume=countProgress;
Properties.Settings.Default.Save();
Environment.Exit(0);//强制应用程序退出
}
}
}
在第二次运行时,循环将被初始化为值640非常感谢您提供了这样一个深入的答案。我一定会尝试。我唯一的问题是,您在if语句中显式设置了countProgress的值。连接可能会在任何阶段丢失,特别是在600。我如何实现这一点?@LindaMotaung so只需删除if条件,以便在每次激发checkCountProgress()时更新和保存设置值谢谢。我使用了这种方法。显然,我不能使用属性变量,我必须在代码中以编程方式执行此操作:-(