Compiler Error CS0026

Keyword 'this' is not valid in a static property, static method, or static field initializer

The this keyword refers to an object, which is an instance of a type. Since static methods are independent of any instance of the containing class, the "this" keyword is meaningless and is therefore not allowed. For more information, see Static Classes and Static Class Members and Objects.


The following example generates CS0026:

// CS0026.cs  
public class A  
   public static int i = 0;  
   public static void Main()  
// CS0026  
      this.i = this.i + 1;
      // Try the following line instead:  
      // i = i + 1;