设为首页收藏本站

嘻皮客娱乐学习网

 找回密码
 中文注册
搜索
打印 上一主题 下一主题
开启左侧

[面试题库] extern是什么意思

[复制链接]
跳转到指定楼层
楼主
发表于 2014-11-30 14:55:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
extern 修饰符用于声明由程序集外部实现的成员函数
经常用于系统API函数的调用(通过 DllImport )。注意,和DllImport一起使用时要加上 static 修饰符
也可以用于对于同一程序集不同版本组件的调用(用 extern 声明别名)
不能与 abstract 修饰符同时使用
示例:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace Example03
{
class Program
{
//注意DllImport是一个Attribute Property,在System.Runtime.InteropServices命名空间中定义
//extern与DllImport一起使用时必须再加上一个static修饰符
[DllImport("User32.dll")]
public static extern int MessageBox(int Handle, string Message, string Caption, int Type);
static int Main()
{
string myString;
Console.Write(“Enter your message: “);
myString = Console.ReadLine();
return MessageBox(0, myString, “My Message Box”, 0);
}
}
}
回复

使用道具 举报

小黑屋|手机版|嘻皮客网 ( 京ICP备10218169号|京公网安备11010802013797  

GMT+8, 2024-4-29 22:27 , Processed in 0.202881 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表