麻烦哪位好心人,交交我,初学者
编写程序定义一个员工类,定义默认构造函数和带参数的构造函数,并采用以上两种方式分别实例化对象,并输入它们的结果。
/// <summary> /// 员工类 /// </summary> public class Person { /// <summary> /// 姓名字段 /// </summary> private string _name; /// <summary> /// 姓名属性 /// </summary> public string Name { get { return _name; } set { _name = value; } } /// <summary> /// 年龄字段 /// </summary> private int _age; /// <summary> /// 年龄属性 /// </summary> public int Age { get { return _age; } set { _age = value; } } /// <summary> /// 员工类的构造函数 /// </summary> /// <param name="name">姓名</param> /// <param name="age">年龄</param> public Person(string name, int age) { this.Name = name; this.Age = age; } } 下面调用: Person p1=new Person("张三",18);
public class Person { //姓名 public string Name { get; set; } //年龄 public int Age { get; set; } public Person() { } public Person(string name, int age) { Name = name; Age = age; } }
上面写的是一个person类,下面是调用
Person p=new Person(); Person p1=new Person("zhangsan",18);