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);
}

 

相关文章:

  • 2022-01-26
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
  • 2021-04-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2022-03-02
  • 2021-10-17
相关资源
相似解决方案