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();
}
}
}
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();
}
}
}
相关文章推荐
- C#重载实例构造函数与构造函数初始化器(转)
- C# 实例构造函数和静态构造函数
- [C#]父类与子类的静态成员变量、实例成员变量、构造函数的执行顺序
- C# Type.GetConstructor() 根据构造函数参数获取实例对象(一)
- 【转】C#父类与子类的静态成员变量、实例成员变量、构造函数的执行顺序
- [C#]父类与子类的静态成员变量、实例成员变量、构造函数的执行顺序
- C# 静态构造函数和实例构造函数
- C#学习基本概念之构造函数之二(实例构造函数)
- C# 静态构造函数和实例构造函数
- C#中私有构造函数的特点和用途实例解析
- C# 父子类_实例_静态成员变量_构造函数的执行顺序
- C#中构造函数和析构函数用法实例详解
- C# 类继承,构造函数 实例
- C#实现单链表(线性表)完整实例
- c# 单实例运行
- C#中Linq查询基本操作使用实例
- .Net ( c# ) 与 Fortran 混合编程实例(二):杆系结构有限元法——平面桁架解答(2)
- 利用C#线程机制实现应用程序的单实例运行
- C#调用WebService实例与开发教程(推荐)
- C#使用SQL DataReader访问数据的优点和实例