简体   繁体   中英

How to import functions from an external namespace onto my project in c sharp

I want to import functions from a different namespace in an external file into my c sharp project. But what's the right method to do it. I copied the.cs file which contains the namespace into my project directory but "using " keyword showing error even the files are from the same directory. To be precise i'm trying to import api functions provided by a company for a hardware which are inside a different.cs file. What's the right way to do it?

Basically, you could create a new project with the same namespace as your imported.cs files have and add it as a project reference. Another method is to modify the namespace in the imported files to match the used namespace in your project.

It really depends on the structure and logic you're importing, personally, I would go with option 1, and maybe even create some interfaces for them, to expose only the functionality I would need to use from them (Facade pattern).

Try to right click the project which you want to add.

Then click on "Add => Existing item...".

Select the.cs file you want and click "Add button".

Now you can using "the.cs file namespace" in your project.

You can add it to your project reference.

Run the below in your terminal.

dotnet add reference [library.csproj]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM