当前位置:编程学习 > C#/ASP.NET >>

C#锐利体验(6.4)

答案:     外部方法
  
    C#引入了extern修饰符来表示外部方法。外部方法是用C#以外的语言实现的方法如Win32 API函数。如前所是外部方法不能是抽象方法。我们看下面的一个例子:
  
  using System;
  using System.Runtime.InteropServices;
  class MyClass
  {
      [DllImport("user32.dll")]
      static extern int MessageBoxA(int hWnd, string msg,string caption, int type);
  
  public static void Main()
      {
          MessageBoxA(0, "Hello, World!", "This is called from a C# app!", 0);
      }
  }
  
  
    程序经编译后执行输出:
  
  
  
    这里我们调用了Win32 API函数int MessageBoxA(int hWnd, string msg,string caption, int type)。
  
  

上一个:C#锐利体验(7.1)
下一个:C#锐利体验(6.3)

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,