日期:2014-05-17  浏览次数:21049 次

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;
        }