PDA

View Full Version : مشکل کوچک با switch



boysilent
دوشنبه 15 خرداد 1391, 20:03 عصر
سلام دوستان این قسمت از برنامم مشکل داره یه نگاهی میندازید؟

protected void Button1_Click(object sender, EventArgs e)
{
string x = DropDownList1.SelectedItem.Value;
int n = int.Parse(x);
if (TextBox1.Text == "" && TextBox2.Text == "" && DropDownList1.SelectedItem.Value == "")

Label1.Text = "فیلدها را پر کنید".ToString();
switch(x){

case 1:
Response.Redirect("teacher.aspx");


}


}
}




فک کنم به متغیرا گیر میده؟؟

canot implicitly convert type int to string

TeacherMath
دوشنبه 15 خرداد 1391, 22:01 عصر
switch(x){

case "1":
Response.Redirect("teacher.aspx");
break;



}

boysilent
دوشنبه 15 خرداد 1391, 22:06 عصر
منظور کار من اینه که یه منوی کشویی که هرکدوم یه valu دارن 1و2و3و4و
اگه یک انتخاب شد یه سری کار انجام بشه اگه 2......

fakhravari
دوشنبه 15 خرداد 1391, 22:19 عصر
switch (n) {
case 0:
printf("You typed zero.");
break;
case 4:
printf("n is an even number.");
case 1:
case 9:
printf("n is a perfect square.");
break;
case 2:
printf("n is an even number.");
case 3:
case 5:
case 7:
printf("n is a prime number.");
break;
case 6:
case 8:
printf("n is an even number.");
break;
default:
printf("Only single-digit numbers are allowed.");
}