110,502
社区成员
发帖
与我相关
我的任务
分享
int GetBoxLocation(int boxIndex)//boxIndex是从值一般都是从1开始,不存在为零的情况
{
return 75+(boxIndex-1)*20;//这里减个1以示从0开始
}
void Main()
{
int sum=0;
for (int i=0;i<10;i++)
{
sum+=GetBoxLocation(i+1);//这里加1以示是第一个
}
}
//从上面代码看,看起来好象从一个box开始的,但多一个"减1加1"感觉有强迫症.
//我想代码是不是可以这样写
int GetBoxLocation(int boxIndex)
{
return 75+boxIndex*20;
}
void Main()
{
int sum=0;
for (int i=0;i<10;i++)
{
sum+=GetBoxLocation(i);
}
}