日期:2014-05-18  浏览次数:20412 次

怎么取得switch的处理结果?
我想让total   =x,     x取得switch的处理结果..帮我想想吧!
int   damage()
{
    int   x;
    switch   ((int)DropDownList_2)
        {
            case   0:     x=0;
            break;
            case   1:     x=1;  
            break;
        }
double   total   =   x;
return   total;
}

------解决方案--------------------
就这样:
int damage()
{
int x;
switch ((int)DropDownList2.SelectedValue)
{
case 0:
x=0;
break;
case 1:
x=1;
break;
default:
x=0;
break;
}
double total = Convert.ToDouble(x); //total就等于x了
return total;
}

------解决方案--------------------
还发现个错误:
int damage() //这里返回int,为什么return total(total是double)的。
所以,LZ改一下返回的数值类型吧!
------解决方案--------------------
double total = DropDownList_2.SelectedIndex;不就行了吗?
------解决方案--------------------
double damage()
{
int x = 0;
switch ((int)DropDownList_2)
{
case 0:
x=0;
break;
case 1:
x=1;
break;
}
double total = Convert.ToDouble(x);
return total;
}
------解决方案--------------------
这个是思路问题吧!!