C#.NET错误:使用了未赋值的局部变量“x” 求高手指导!

privatevoidbutton1_Click(objectsender,EventArgse){intage,eq;//年龄,智商,情商;stringiq;charn... private void button1_Click(object sender, EventArgs e)
{

int age,eq;//年龄,智商,情商;
string iq;
char name;//英文名,定义数组
{
int x;
if
(listBox1.Text == "白羊座 3月21日--4月19日 ")
x = 0;
else if
(listBox1.Text == "金牛座 4月20日--5月20日")
x = 5;
else if
(listBox1.Text == "双子座 5月21日--6月21日")
x = 8;
else if
(listBox1.Text == "巨蟹座 6月22日--7月22日")
x = 3;
else if
(listBox1.Text == "狮子座 7月23日--8月22日")
x = 4;
else if
(listBox1.Text == "处女座 8月23日--9月22日")
x = 6;
else if
(listBox1.Text == "天秤座 9月23日--10月23日")
x = 9;
else if
(listBox1.Text == "天蝎座 10月24日--11月21日")
x = 7;
else if
(listBox1.Text == "射手座 11月22日--12月21日")
x = 11;
else if
(listBox1.Text == "摩羯座 12月22日--1月19日")
x = 10;
else if
(listBox1.Text == "水瓶座 1月20日--2月18日")
x = 12;
else if
(listBox1.Text == "双鱼座 2月19日--3月20日")
x = 1;

age = int.Parse(textBox1.Text);
name = char.Parse(textBox2.Text);
y = age+ x;
iq = Convert.ToString(age + x);
eq = name;
textBox4.Text = iq;
textBox3.Text = Convert.ToString(eq );
展开
 我来答
朝阳里的期许
2012-03-21 · 超过24用户采纳过TA的回答
知道答主
回答量:88
采纳率:0%
帮助的人:57.8万
展开全部
你需要给x赋一个初期值(默认值),编译器认为可能会执行不到你12种情况的任何一种情况
更多追问追答
追问
我赋了初值之后运行就不会执行那12种情况,直接就以初值来计算了~~难道是获取listbox1出问题了?
追答
你自己设个断点调试下就知道了啊,看看listBox1.Text在你调试的时候是什么值
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式