Compiler Error CS0027
Keyword 'this' is not available in the current context
The this 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:
C#
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();
}
}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET feedback
.NET is an open source project. Select a link to provide feedback: