死循环的原因:
i++ 和 ++i的基本功能是相同的,都是对变量i进行自增1运算,从功能上讲相当于i =i+1 ;
两个的区别在于:
int i=1,a=0;
i++ 先运算在赋值
,例如 a = i++,先运算a=i,后运算i = i+1,所以结果是a == 1;
++i 先赋值在运算
,例如 a = ++i,先运算i=i+1,后运算a = i,所以结果是a == 2。
public ResultEntity SyncDataXml(string interfaceCode, SyncDataParam param)
{
int curPage = 1;
int nextPage = 2;
int totalPage = 2;
if(param.Page != 0)
{
curPage = param.Page;
nextPage = curPage++;// 死循环的原因
}
//递归
if(nextPage <= totalPage)
{
var nextParam = new SyncDataParam
{
LastUpdateTime = param.LastUpdateTime,
Page = nextPage
};
result = SyncDataXml(interfaceCode, nextParam);
}
return result;
}
public ResultEntity SyncDataXml(string interfaceCode, SyncDataParam param)
{
int curPage = 1;
int nextPage = 2;
int totalPage = 2;
if(param.Page != 0)
{
curPage = param.Page;
nextPage = ++curPage;// 解决
}
//递归
if(nextPage <= totalPage)
{
var nextParam = new SyncDataParam
{
LastUpdateTime = param.LastUpdateTime,
Page = nextPage
};
result = SyncDataXml(interfaceCode, nextParam);
}
return result;
}
标签:运算,++,param,int,curPage,死循环,nextPage
From: https://www.cnblogs.com/qian-chang/p/death-cycle-caused-by-different-operations-of-i-and-i