首页 > Windows开发 > 详细

C#外部方法

时间:2015-09-09 11:07:09      阅读:238      评论:0      收藏:0      [点我收藏+]
using System;
using System.Runtime.InteropServices;
using System.Text;
/*
 * 外部方法是在声明中没有实现的方法,常常是C#之外的编程语言编写的。
 * 1、用extern修饰符标记,在类的声明中没有实现,它的实现被分号取代
 * 2、声明和实现的连接是依赖实现的。常常使用DllImport特性完成
 */
namespace ExternMethod
{
    class MyClass
    {
        [DllImport("kernel32",SetLastError=true)]
        public static  extern int GetCurrentDirectory(int a,StringBuilder b);
    }
    class Program
    {
        static void Main(string[] args)
        {
            const int MaxDirLength = 250;
            StringBuilder sb = new StringBuilder();
            sb.Length = MaxDirLength;
            MyClass.GetCurrentDirectory(MaxDirLength, sb);
            Console.WriteLine(sb);
            Console.ReadKey();
        }
    }
}

C#外部方法

原文:http://www.cnblogs.com/sulong/p/4793842.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!