C# Error CS1511 – Keyword ‘base’ is not available in a static method

C# Error

CS1511 – Keyword ‘base’ is not available in a static method

Reason for the Error & Solution

Keyword ‘base’ is not available in a static method

The keyword was used in a method. base can only be called in an instance constructor, instance method, or instance accessor.

Example

The following sample generates CS1511.

// CS1511.cs  
// compile with: /target:library  
public class A  
{  
   public int j = 0;  
}  
  
class C : A  
{  
   public void Method()  
   {  
      base.j = 3;   // base allowed here  
   }  
  
   public static int StaticMethod()  
   {  
      base.j = 3;   // CS1511  
      return 1;  
   }  
}  

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...