C#中调用方法提示类型转换不了
privatevoidForm1_Load(objectsender,EventArgse){PersonZhangSan=newPerson()ZhangSan.age...
private void Form1_Load(object sender, EventArgs e) { Person ZhangSan = new Person() ZhangSan.age = "ZhangSan"; this.textBox1.Text = ZhangSan.say(); } } public class Person { public string name; public int age; public string say() { return "中华"; } } }如题,当我把实例中的ZhangSan.age改成.name就能调用下面的方法了,但改成age为什么不可以呢,显示类型不对,求解
展开
展开全部
private void Form1_Load(object sender, EventArgs e) { Person ZhangSan = new Person() ZhangSan.age = "ZhangSan"; this.textBox1.Text = ZhangSan.age.ToString(); //输出年龄 // this.textBox1.Text = ZhangSan.name; //Name } } public class Person { public string name; public int age; public string say() { return "中华"; } }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询