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

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

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...