Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Compiler Error CS0026
Collapse the table of content
Expand the table of content

Compiler Error CS0026

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

The this (C# Reference) 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 (C# Programming Guide) and Objects (C# Programming Guide).

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;

Community Additions

© 2015 Microsoft