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

查看:580
本文介绍了如何在项目中使用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.

参考:


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

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

    注意:如果要使用的DLL位于同一项目中,显然使用Browse是错误的形式。相反,右键单击项目,然后单击添加引用,然后从项目选项卡中选择适当的类:


  3. 点击确定。

添加使用子句:

using [namespace];到您要引用库的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天全站免登陆