Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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();
}
}
}