C# Error CS1018 – Keyword ‘this’ or ‘base’ expected

C# Error

CS1018 – Keyword ‘this’ or ‘base’ expected

Reason for the Error & Solution

Keyword ‘this’ or ‘base’ expected

The compiler encountered an incomplete constructor declaration.

Example

The following example generates CS1018, and suggests several ways to resolve the error:

// CS1018.cs  
public class C  
{  
}  
  
public class a : C  
{  
    public a(int i)  
    {  
    }  
  
    public a () :   // CS1018  
    // possible resolutions:  
    // public a () resolves by removing the colon  
    // public a () : base() calls C's parameterless constructor  
    // public a () : this(1) calls the assignment constructor of class a  
    {  
    }  
  
    public static int Main()  
    {  
        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...