C# Error CS0027 – Keyword ‘this’ is not available in the current context

C# Compiler Error Message

CS0027 Keyword ‘this’ is not available in the current context

Reason for the Error

You will receive this error if you use this keyword outside of a property , function or constructor. For example, try compiling the below code snippet.

using System;
public class DeveloperPublish
{
    public int result = this.Function1(); 
    public int Function1()
    {
        return 1;
    }

    public static void Main()
    {
        Console.WriteLine("Main");
    }
}

You will receive the error “CS0027 Keyword ‘this’ is not available in the current context” because this.Function1() is used in a wrong place.

C# Error CS0026 - CS0027 Keyword 'this' is not available in the current context

Solution

To resolve this error, you’ll need to modify your code so that use of this keyword is moved inside a property, function or even a constructor.

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...