当前位置:首页 > 网络编程 > 软件语言 > .NET > C#2.0

C#2.0

点击次数:74 次 发布日期:2008-11-06 08:08:59 作者:源代码网
源代码网推荐
广告载入中

源代码网整理以下extern 修饰符用于声明在外部实现的方法。extern 关键字常用于定义外部程序集别名,使得可以从单个程序集中引用同一组件的不同版本。
  extern 修饰符的常见用法是在使用 Interop 服务调入非托管代码时与 DllImport 属性一起使用;在这种情况下,该方法还必须声明为 static。如:

源代码网整理以下[DllImport("avifil32.dll")]

源代码网整理以下private static extern void AVIFileInit();在该示例中,程序接收来自用户的字符串并将该字符串显示在消息框中。程序使用从 User32.dll 库导入的 MessageBox 方法。using System;

源代码网整理以下using System.Runtime.InteropServices; 软件开发网 www.mscto.com

源代码网整理以下class MainClass

源代码网整理以下{

源代码网整理以下    [DllImport("User32.dll")]

源代码网整理以下    public static extern int MessageBox(int h, string m, string c, int type);

源代码网整理以下 

源代码网整理以下    static int Main()

源代码网整理以下    {

源代码网整理以下        string myString;

源代码网整理以下        Console.Write("Enter your message: ");

源代码网整理以下        myString = Console.ReadLine();

软件开发网 www.mscto.com

源代码网整理以下        return MessageBox(0, myString, "My Message Box", 0);

源代码网整理以下    }

源代码网整理以下}

软件开发网 www.mscto.com

源代码网整理以下 

源代码网整理以下 


源代码网推荐

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华