您的位置:首页 > 编程语言 > C#

C#实例构造函数

2015-03-21 00:52 176 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace instanceConstruct
{
class Employee
{
private string name;
public int Age { get; set; }
private double salary=2000;
public double Salary
{
get { return salary; }
set { salary = value; }
}

public Employee(string name)
{
this.name = name;
}
public Employee(string name, int age, double salary)
{
this.name = name;
this.Age = age;
this.salary = salary;
}
public void display()
{
Console.WriteLine("{0},{1},{2}", name, Age, salary);
}
}
class Program
{
static void Main(string[] args)
{
Employee emp = new Employee("李明");
emp.display();

Employee emp1 = new Employee("李明1",23,3000);
emp1.display();

Employee emp2 = new Employee("李明2") { Age = 23, Salary = 4000 };
emp2.display();

Console.ReadLine();

}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: