using System; class A { public int count; public void F() { Console.WriteLine(this.count); }
public static string name; public static void G() { Console.WriteLine(name); } } class Test { public static void Main() { A a1=new A(); A a2=new A(); a1.F(); a1.count=1; a2.F(); a2.count=2;
A.name="CCW"; A.G(); } }
class Employee { public Employee(string name, string alias) { this.name = name; this.alias = alias; } } 将对象作为参数传递到其他方法时也要用this表达,例如:
CalcTax(this); 声明索引器时this更是不可或缺,例如:
public int this [int param] { get { return array[param]; } set { array[param] = value; } }
文章评论(0条评论)
登录后参与讨论