您的位置:首页 > 编程语言 > C#

C#中创建和使用动态链接库

2017-09-22 16:29 288 查看
动态链接库英文为DLL,是DynamicLinkLibrary的缩写形式,DLL是一个包含可由多个程序同时使用的代码和数据的库,它有助于共享数据和资源。

(一)创建动态链接库

1)新建一个类库



2)编写该类库

例如:

usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;

namespaceDllTest
{
publicclassMyClass
{
publicvoidShowMessage()
{
Console.WriteLine("你已成功调用了动态链接!");
Console.ReadLine();
}
}
}


3)生成动态链接库



(二)使用动态链接库

1)添加引用 

           右击项目-添加引用-浏览找到本地的dll文件





2)using该dll文件里面代码的名称空间

例如:

usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
//using要引用的dll文件的命名空间
usingDllTest;

namespaceDllExample
{
classProgram
{
staticvoidMain(string[]args)
{
DllTest.MyClassmyTest=newDllTest.MyClass();
myTest.ShowMessage();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: