Compiler Error CS0027
Keyword 'this' is not available in the current context
The this (C# Reference) keyword was found outside of a property, method, or constructor.
To fix this error, either modify the statement to eliminate use of the this keyword, and/or move part or all of the statement inside a property, method, or constructor.
The following example generates CS0027:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication3
{
class MyClass
{
int err1 = this.Fun() + 1; // CS0027
public int Fun()
{
return 10;
}
public void Test()
{
// valid use of this
int err = this.Fun() + 1;
Console.WriteLine(err);
}
public static void Main()
{
MyClass c = new MyClass();
c.Test();
}
}
}