C#锐利体验(6.4)

C#锐利体验(6.4)


Author: 李建忠  &;nbspFrom:Internet


                外部方法
 
    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)。
 
    (2005-7-18:04:23)
 感谢原创者的辛勤劳动,希望对您有所帮助,转载请注明原出处。
 警告:持续变种木马正在发起农历新年攻势!
 您可能对 [C#] 的这些文章也感兴趣:
C# 3.0中的分部方法
.net程序员的盲点(一):参数修饰符ref,out ,params的区别
.net程序员的盲点(二):两个“属性”引起的歧异
使用VBA.NET压缩备份C#工程
C#处理数码相片之马赛克的实现
如何把图片插入Excel的一个单元格中
c#写的五子棋程序
如何杀死Word,Excel等进程?
HttpClient, 使用C#操作Web
C#精髓集合(1)
C#精髓集合(2)
C#精髓集合(3)