当前位置: 代码迷 >> C# >> C#报错应用未赋值的局部变量a
  详细解决方案

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

热度:4802   发布时间:2013-02-25 00:00:00.0
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;
        }
  相关解决方案