How do I use a C# Class Library in a project?

后端 未结 9 1899
北恋
北恋 2020-11-28 05:23

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?

相关标签:
9条回答
  • 2020-11-28 05:42

    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.

    Adding a reference:

    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.

    Adding a using clause:

    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;
    
    0 讨论(0)
  • 2020-11-28 05:45

    In the Solution Explorer window, right click the project you want to use your class library from and click the 'Add Reference' menu item. Then if the class library is in the same solution file, go to the projects tab and select it; if it's not in the same tab, you can go to the Browse tab and find it that way.

    Then you can use anything in that assembly.

    0 讨论(0)
  • 2020-11-28 05:46

    Here is a good article on creating and adding a class library. Even shows how to create Methods through the method wizard and how to use it in the application

    0 讨论(0)
  • 2020-11-28 05:49

    Right Click on Project--> Add--> New Project-->click on Class Library.

    Now your class library is created as class1.cs

    Right Click on References(of your program/console app)

    -->Add Reference-->classLibrary1(whatever you named) Now mention "using ClassLibrary1" in your program/console app

    Now u can easily call the method/property in your console app

    0 讨论(0)
  • 2020-11-28 05:56

    You need to add a reference to your class library from your project. Right click on the references folder and click add reference. You can either browse for the DLL or, if your class libaray is a project in your solution you can add a project reference.

    0 讨论(0)
  • 2020-11-28 05:56
    1. Add a reference to your library
    2. Import the namespace
    3. Consume the types in your library
    0 讨论(0)
提交回复
热议问题