首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

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

2013-02-19 
C#报错使用未赋值的局部变量a如题,代码如下class personproperties{public string namepublic string age

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

热点排行