- 爱易网页
-
C#教程
- C#中foreach有关问题
日期:2014-05-18 浏览次数:20931 次
C#中foreach问题
代码如下:
[code=C#][/code]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace label_use
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 1900; i <= 2050; i++)
{
comboBox1.Items.Add(i);
}
comboBox1.Text = DateTime.Now.Year.ToString();
}
private void label2_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
int intyear = Convert.ToInt32(comboBox1.Text);
string strtext = "";
switch (intyear %12)
{
case 4:
strtext="鼠";
break;
case 5:
strtext = "牛";
break;
case 6:
strtext = "虎";
break;
case 7:
strtext = "兔";
break;
case 8:
strtext = "龙";
break;
case 9:
strtext = "蛇";
break;
case 10:
strtext = "马";
break;
case 11:
strtext = "羊";
break;
case 0:
strtext = "猴";
break;
case 1:
strtext = "鸡";
break;
case 2:
strtext = "狗";
break;
case 3:
strtext = "猪";
break;
}
foreach (RadioButton rbtn in groupBox1 .Controls )
{
if (rbtn.Text==strtext)
{
rbtn.Checked = true;
}
}
}
private void RadioButton4_CheckedChanged(object sender, EventArgs e)
{
}
private void radioButton12_CheckedChanged(object sender, EventArgs e)
{
}
}
}
问题在如下图:
在调试是为什么会出现“当从一个数字执行强制转换时,值必须是一个小于无限大的数字”这样的排错提示呢?求解。
右键有关问题