C#中extern的使用

extern 修饰符用于声明 由程序集外部实现的成员函数经常用于系统API函数的调用(通过 DllImport )

注意,和DllImport一 起使用时要加上 static 修饰符也可以用于对于同一程序集不同版本组件的调用(用 extern 声明别名) 不能与 abstract 修饰符同时使用 。

class Program
    {
        [DllImport("User32.dll")]
        public static extern int MessageBox(int Handle, string Message, string Caption, int Type);
        static void Main(string[] args)
        {
            string myString;
            Console.Write("Enter your message:");
            myString = Console.ReadLine();
            MessageBox(0, myString, myString, 0);

        }
    }
原文地址:https://www.cnblogs.com/heyanpeng/p/3372491.html