I am completely new to using Visual Studio 2013 Ultimate and C# and I am trying to figure out how to simply import a class that exists in another project into my console application.
I have another project named Project1
that contains a CreditCard.cs
file. I have tried the following for importing the CreditCard
class:
using Project1.CreditCard
Can anyone please point me in the right direction or tell me how I might import a class in C#?
在解决方案资源管理器中,右键单击您的项目并转到添加==>现有项目,然后浏览到现有类的路径。
You right click on the project (not solution) that you want having the reference. So click on your new project, choose Add | References --- then in the dialog, choose Solution on the left, and find your CreditCard project and add it. It'll add the reference, and you can then use the Using in your code.
When you say another project do you mean two projects in the same solution? if so, you have to reference the project(Project1) with the class in the other project(Project2) by doing so:
Now in your project(Project2) you can do "using Project1(name of your project)" or "using Project1.FolderName" if your class is in a folder to use that class and then:
CreditCard creditCard = new CreditCard();
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.