我試圖打印出星期幾,當一個數字輸入到文本框中,但它似乎並沒有在標籤上打印一旦我點擊按鈕,當我運行代碼似乎工作正常,直到當我輸入一個值,然後單擊按鈕,沒有任何反應。標籤priting via按鈕
private void button1_Click(object sender, EventArgs e)
{
int dayOfWeek = Convert.ToInt32(textBox1);
String dayName = null;
switch (dayOfWeek)
{
case 1:
dayName = "Sunday";
break;
case 2:
dayName = "Monday";
break;
case 3:
dayName = "Tuesday";
break;
case 4:
dayName = "Wednesday";
break;
case 5:
dayName = "Thursday";
break;
case 6:
dayName = "Friday";
break;
case 7:
dayName = "Saturday";
break;
String stndrd = null;
if (dayOfWeek == 1)
{
stndrd = dayName;
label1.Text = (stndrd);
}
else if (dayOfWeek == 2)
{
stndrd = dayName;
label1.Text = (stndrd);
}
else if (dayOfWeek == 3)
{
stndrd = dayName;
label1.Text = (stndrd);
}
else if (dayOfWeek == 4)
{
stndrd = dayName;
label1.Text = (stndrd);
}
else if (dayOfWeek == 5)
{
stndrd = dayName;
label1.Text = (stndrd);
}
else if (dayOfWeek == 6)
{
stndrd = dayName;
label1.Text = (stndrd);
}
else if (dayOfWeek == 7)
{
stndrd = dayName;
label1.Text = (stndrd);
}
else if (dayOfWeek == null)
{
stndrd = "Mad Day!!!";
label1.Text = (stndrd);
沒有它編譯一個更簡單的方法(在C.Evenhuis的建議延長)? – 2014-10-01 09:48:51