【发布时间】:2011-05-05 20:18:08
【问题描述】:
我在编写从 hex 到 bin、dec 到 bin 等的转换器时遇到问题。这是我的代码,当我调试它时出现错误“使用未分配的局部变量 Dec_Int10”,你能帮帮我吗?我该如何解决这个错误?
protected void Button_Click (object sender, Event Args e)
{
if (Page.IsValid)
{
int Dec_Int10;
if(!(string.IsNullOrEmpty(TextBox1.Text)))
{
Dec_Int10 = Convert.ToInt32(TextBox1.Text, 10)));
}
if(!(string.IsNullOrEmpty(TextBox2.Text)))
{
Dec_Int10 = Convert.ToInt32(TextBox2.Text, 16)));
}
if(!(string.IsNullOrEmpty(TextBox3.Text)))
{
Dec_Int10 = Convert.ToInt32(TextBox3.Text, 8)));
}
if(!(string.IsNullOrEmpty(TextBox4.Text)))
{
Dec_Int10 = Convert.ToInt32(TextBox4.Text, 2)));
}
string Dec_Str10 = Convert.ToString(Dec_Int10, 10);
string Hex_Str16 = Convert.ToString(Dec_Int10, 16);
string Oct_Str8 = Convert.ToString(Dec_Int10, 8);
string Bin_Str2 = Convert.ToString(Dec_Int10, 2);
TextBox1.Text = Dec_Str10;
TextBox2.Text = Hex_Str16;
TextBox3.Text = Oct_Str8;
TextBox4.Text = Bin_Str2;
}
}
【问题讨论】:
-
一个精确的错误信息?!?从来没有!
标签: c# asp.net .net-3.5 .net-4.0