您现在的位置是: 软件 > 开发者网络 > 微软开发专栏 > Visual Studio.net专栏 > C#专区 > 正文


-网页表格制作速查手册
-Visual C++ MFC/ATL开发
-Visual C++ 数据库开发
-打开闪烁的新世界:体验Flash MX

C#锐利体验(六)
2002-04-12· ·李建忠··Microsoft

上一页  1 2 3 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)。

上一页  1 2 3 4  

■ 相关内容
 锋利的新语言:C#提供了C++的功能和Visual Basic的简单性
 DirectDraw之C#入门攻略
 使用C#轻松编写.Net组件
 使用C#开发一个简单的P2P应用
 Visual C# 对话框全接触
 从C/C++到C#的锐利之路
 C#中调用API
 在C#中使用微软AGENT之TTS
 C#与Java述评
 C#的多线程机制探索
感谢 访问天极网,如果您觉得该文章涉及版权问题,请看这里!