編譯器錯誤 CS0027
關鍵字 'this' 在目前內容中無法使用
this 關鍵字位於屬性、方法或建構函式外部。
若要修正這個錯誤,請修改陳述式,使其不需要使用 this
關鍵字,及/或移動屬性、方法或建構函式內的局部或整個陳述式。
下列範例會產生 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();
}
}
}