输入一个整数,分段处理有什么好方法?
protected string RetImg(int point)
{
string strImg = string.Empty;
if(point > 0 && point <= 10)
{
strImg = "../xin/xinxin1.gif ";
}
else if (point > 10 && point <= 40)
{
strImg = "../xin/xinxin2.gif ";
}
else if (point > 40 && point <= 90)
{
strImg = "../xin/xinxin3.gif ";
}
else if (point > 90 && point <= 150)
{
strImg = "../xin/xinxin4.gif ";
}
else if (point > 150 && point <= 250)
{
strImg = "../xin/xinxin5.gif ";
}
else if (10-20个条件)
{
strImg = ".. ";
}
else
{
strImg = "../xin/xinxin1.gif ";
}
return strImg;
}
有什么好的解决方法
------解决方案--------------------效率都差不多,得可简化一下代码量
protected string RetImg(int point)
{
string strImg = string.Empty;
if(point <=0) return strImg;
int[] ary = new int[]{10,30,50,60,100,200};
int iTotal = 0 ;
for(int i=0;i <ary.Length;i++)
{
iTotal += ary[i];
if( point <= iTotal)
{
return "../xin/xinxin "+(i+1).ToString();
}
}
return strImg;
}