码迷,mamicode.com
首页 > Windows程序 > 详细

C#外部方法

时间:2015-09-09 11:09:11      阅读:208      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!