編譯器錯誤 CS0601
更新:2007 年 11 月
錯誤訊息
DllImport 屬性必須用在標記為 'static' 和 'extern' 的方法上
DllImport 屬性 (Attribute) 用在沒有正確存取關鍵字的方法上。
下列範例會產生 CS0601:
// CS0601.cs
using System.Runtime.InteropServices;
using System.Text;
public class C
{
[DllImport("KERNEL32.DLL")]
extern int GetCurDirectory(int bufSize, StringBuilder buf); // CS0601
// Try the following line instead:
// static extern int GetCurDirectory(int bufSize, StringBuilder buf);
}
public class MainClass
{
public static void Main ()
{
}
}