c#

  根据提供的员工类,定义三个版本的构造函数,版本一根据参数初始化工号、姓名,性别为男,工资为1200;版本二根据参数初始化工号、姓名、性别,工资为1200;版本三根据参数初始化工号、姓名、性别和工资。
使用三个版本的构造函数创建三个对象,并分别输出工号验证初始化的字段值。
用C#语言怎么编写?急!!!

解决方案 »

  1.   


        public class Person
        {
            string worknum;
            string name;
            string sex;
            float salary;
            public Person(string _worknum,string _name)
            {
                this.worknum = _worknum;
                this.name = _name;
                this.sex = "男";
                this.salary = 1200;
            }
            public Person(string _worknum, string _name,string _sex)
            {
                this.worknum = _worknum;
                this.name = _name;
                this.sex = _sex;
                this.salary = 1200;
            }
            public Person(string _worknum, string _name, string _sex,float _salary)
            {
                this.worknum = _worknum;
                this.name = _name;
                this.sex = _sex;
                this.salary = _salary;
            }
        }实例就通过这三个构造函数去做
      

  2.   

    class yuangong
    {
       int yuangonghao;
       string xingming;
       string xingbie = "男";
       int gongzi=1200;
    public yuangong(int yuangonghao1,string xingming1)
      {
    yuangonghao = yuangonghao1;
    xingming=xingming1;  }   public yuangong(int yuangonghao1,string xingming1,string xingbie1)
      {
    yuangonghao = yuangonghao1;
    xingming=xingming1;
    xingbie=xingbie1;  } public yuangong(int yuangonghao1,string xingming1,string xingbie1,int gongzi1)
      {
    yuangonghao = yuangonghao1;
    xingming=xingming1;
    xingbie=xingbie1;
    gongzi=gongzi1;  }}
      

  3.   


            static void Main(string[] args)
            {
                Employee e1 = new Employee(1, "John");
                Console.WriteLine(e1.No);
                Employee e2 = new Employee(2, "Smith", "男");
                Console.WriteLine(e2.No);
                Employee e3 = new Employee(3, "Paul", "男", 2400);
                Console.WriteLine(e3.No);
            }        public class Employee
            {
                public int No { get; set; }
                public string Name { get; set; }
                public string Sex { get; set; }
                public double Salary { get; set; }            public Employee(int no, string name, string sex, double salary)
                {
                    this.No = no;
                    this.Name = name;
                    this.Sex = sex;
                    this.Salary = salary;
                }            public Employee(int no, string name, string sex)
                    : this(no, name, sex, 1200)
                {            }            public Employee(int no, string name)
                    : this(no, name, "男", 1200)
                {            }
            }
      

  4.   


        public class Person
        {
            string worknum;
            string name;
            string sex;
            float salary;
            public Person(string _worknum, string _name)
            {
                this.worknum = _worknum;
                this.name = _name;
                this.sex = "男";
                this.salary = 1200;
            }
            public Person(string _worknum, string _name, string _sex)
            {
                this.worknum = _worknum;
                this.name = _name;
                this.sex = _sex;
                this.salary = 1200;
            }
            public Person(string _worknum, string _name, string _sex, float _salary)
            {
                this.worknum = _worknum;
                this.name = _name;
                this.sex = _sex;
                this.salary = _salary;
            }
            public override string ToString()
            {
                return string.Format("worknum:{0},name:{1},sex:{2},salary:{3}", this.worknum, this.name, this.sex, this.salary);
            }
        }
     
        class Program
        {
        
            static void Main(string[] args)
            {
                Person person0 = new Person("123", "kk");
                Console.WriteLine( person0.ToString());
                Person person1 = new Person("123", "kk","mm");
                Console.WriteLine( person1.ToString());
                Person person2 = new Person("123", "kk","mm",1234);
                Console.WriteLine( person2.ToString());
                Console.ReadKey();
            }          
         }