Pages

Monday, May 13, 2013

this keyword in c#

"this" keyword is used to  refer the current instance or current object
->local variable will be more priority to global variable(if they are same class)
->Static member functions do not have a this pointer
->The this keyword can be used to access members from within constructors, instance methods, and instance accessors.

Sample Code:

{
 A a =new A();
 a.m(12);
 Response.Write(a.x);
  }
}
public class A
  {
   public int x=20; // global variable
  public void m(int x);
    {
        this.x=this.x+x;
     }
}

No comments:

Post a Comment