读书人

C#报错应用未赋值的局部变量a

发布时间: 2013-02-19 11:11:40 作者: rapoo

C#报错使用未赋值的局部变量a
如题,代码如下


class personproperties
{
public string name;
public string age;
public string sex;
public Bitmap photo;
}
private void button1_Click(object sender, EventArgs e)
{
personproperties a;
a.name = textBox1.Text;
a.age = textBox2.Text;
a.sex = textBox3.Text;
}

[解决办法]

class personproperties
{
public string name {get;set;};
public string age {get;set;};
public string sex {get;set;};
public Bitmap photo {get;set;};
}
private void button1_Click(object sender, EventArgs e)
{
personproperties a=new personproperties ();
a.name = textBox1.Text;
a.age = textBox2.Text;
a.sex = textBox3.Text;
}

读书人网 >C#

热点推荐