如何在项目中使用C#类库? [英] How do I use a C# Class Library in a project?

查看:161
本文介绍了如何在项目中使用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文件的顶部,你想用它引用和使用条款。

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.

添加引用:

1)在Visual Studio中,单击项目,然后添加引用。

2)单击浏览选项卡,找到要添加引用的DLL。

注:显然使用浏览是坏的形式,如果你想要使用的DLL是在同一个项目。相反,用鼠标右键单击该项目,然后单击添加引用,然后选择从项目选项卡中的相应等级:


3)单击确定。

1) In Visual Studio, click Project, and then Add Reference.
2) Click the Browse tab and locate the DLL you want to add a reference to.
NOTE: Apparently using Browse is bad form if the DLL you want to use is in the same project. Instead, right-click the Project and then click Add Reference, then select the appropriate class from the Project tab:
3) Click OK.

添加使用条款:

添加使用[命名空间];要在其中引用库中的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆