简体   繁体   中英

How to import a class from another project in Visual Studio 2013 Ultimate

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:

  • typing using Project1.CreditCard
  • going to the Solution Explorer and then looking for "References" which I could not find, to try to include the class as an imported class.

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:

  1. Left click on the project(Project2) that you want to add the reference
  2. Go to Add -> Reference -> Solution
  3. Target the project(Project1) you want to add and click OK

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.

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