码迷,mamicode.com
首页 > Windows程序 > 详细

c#基础知识 构造方法

时间:2016-12-19 11:17:25      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:局部变量   class   pre   word   span   line   ons   构造   调用   

  <summary>
    /// 构造方法的主要作用是完成对象的初始化工作
    /// 构造方法的方法名与类名相同
    /// 构造方法没有返回类型,也不写void.
    ///
    /// 构造方法不能显示地直接调用,而是用new来调用
    /// person p = new person("tomme",20)
    ///
    /// </summary>
    public class Employee
    {
        [Key]
        public int EmployeeId { get; set; }
        public string FistName { get; set; }
        public string LastName { get; set; }

        public int Salary { get; set; }
    }

 

方法的重载

public void sayhello(){
Console.WriteLine("hello word"+name);
}

public void sayhello(Person another){
Console.WriteLine("hello word"+anpther.name);
}

方法的签名:方法名及参数个数及类型构成(参数名不算)

 

this对象本身,常用于

(1)访问这个对象的字段与方法

(2)区分字段和局部变量

public Person(int age,string name){
this.age=age;
this,name=name;
}

(3)构造方法调用

 

写类:定义字段和方法

 

c#基础知识 构造方法

标签:局部变量   class   pre   word   span   line   ons   构造   调用   

原文地址:http://www.cnblogs.com/zry2510/p/6196368.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!