如何在项目中使用 C# 类库? [英] How do I use a C# Class Library in a project?
本文介绍了如何在项目中使用 C# 类库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 C# 中创建了一个新的类库,并想在我的其他 C# 项目之一中使用它 - 我该怎么做?
I've created a new Class Library in C# and want to use it in one of my other C# projects - how do I do this?
推荐答案
在项目中添加对它的引用,并在 CS 文件顶部要使用它的位置添加 using 子句.
Add a reference to it in your project and a using clause at the top of the CS file where you want to use it.
添加引用:
- 在 Visual Studio 中,单击项目",然后单击添加引用".
- 单击浏览"选项卡并找到要添加引用的 DLL.
注意:如果您要使用的 DLL 在同一个项目中,显然使用 Browse 是错误的形式.相反,右键单击项目,然后单击添加引用,然后从项目选项卡中选择适当的类: - 点击确定.
添加 using 子句:
Adding a using clause:
添加使用[命名空间];"到要引用库的 CS 文件.因此,如果您要引用的库具有名为 MyLibrary 的命名空间,请将以下内容添加到 CS 文件中:
Add "using [namespace];" to the CS file where you want to reference your library. So, if the library you want to reference has a namespace called MyLibrary, add the following to the CS file:
using MyLibrary;
这篇关于如何在项目中使用 C# 类库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文