C#外部方法
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();}}}
轉載于:https://www.cnblogs.com/sulong/p/4793842.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
- 上一篇: Windows下tcp参数优化
- 下一篇: windows2008吃尽内存的解决办法