当前位置: 移动技术网 > IT编程>开发语言>c# > C#学习基础概念二十五问第1/4页

C#学习基础概念二十五问第1/4页

2019年07月18日  | 移动技术网IT编程  | 我要评论
注:本文部份资料来自网络,如有侵权,请与我联系,我会在第一时间声明引用或将其删除!     当初学 c# 时是找

3.extern 是什么意思?
答:
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); 
        } 
    } 


2

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网