C# extern关键字

extern关键字表示函数的实现在程序集外部

多用于调用winAPI函数(配合DllImport使用),在和DllImport使用时需要加上static,不能和abstract同时使用,因为方法的实现在外部。

用DllImport需要引入using System.Runtime.InteropServices命名空间

 

[DllImport("User32.dll")]
public static extern int
MessageBox(int Handle, string Message, string Caption, int Type);
static int
Main()
{
 
  return MessageBox(0, "Hello World", "My Message Box", 0);
}

 

posted @ 2010-06-01 18:24  JerryT  阅读(1413)  评论(0编辑  收藏  举报