C#基础-面向对象/static/this

C#基础-面向对象
基本跟java一样,区别:
1.内部成员,包内可见用:internal
2.派生类(继承):class Class2:Class1{}
3.总结this与static的用法

This
this的用法再次小结一下:
例如:
构造函数
public Employee(string name, decimal salary)
{
      this.name = name;//denote this construction method.
      this.salary = salary;
}

method(this)// denote this current instance of class
Sample of  static
 1  using  System;
 2 
 3  class  Employee
 4  {
 5       public   static   decimal  salary; // static member
 6       public   string  name; // non-static member
 7       public   static   void  setSalary( decimal  B) // static method
 8      {
 9          salary  =  B; // right,equivalence declaration:Employee.Salary = B;
10      }
11       public   void  setName( string  N) // non-static memeber
12      {
13          name  =  N; // right,equivalence declaration:this.name = N;
14      }
15  }
16 
17  public   class  Sample
18  {
19       public   static   void  Main()
20      {
21          Employee.salary  =   8000.0m ; // right,static member can access through name of class
22          Employee.setSalary( 8000.0m ); // right,static method can access through name of class
23          Employee  e  =   new  Employee();
24          e.name  =   " Einstein " // right, non-static memeber must access through the instance of class
25          e.setName( " Einstein " ); // right,non-static method must access through the instence of class
26          Console.WriteLine( " name of stuff is:{0}\nstuff salary:{1} " ,e.name,Employee.salary);
27      }    
28  }

转载于:https://www.cnblogs.com/nut/archive/2007/05/24/757903.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值