編譯器錯誤 CS0027
更新:2007 年 11 月
錯誤訊息
關鍵字 'this' 在目前內容中無法使用
this (C# 參考) 關鍵字出現在屬性 (Property)、方法或建構函式 (Constructor) 之外。
若要更正這個錯誤,請修改陳述式不要使用 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();
}
}
}