Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call classes from one Project in another Project?

Excuse the incredibly silly question but im new to C# . I just can’t figure out how to use classes from one Project in another Project.

Lets say I want to take a string from Project1 to Project2 and have Project2 print said string .

I reference Project2 from Project1 with the “add reference” menu , then I add “using Project2” and then I write this to trying and call "print" from "ClassA" in "Project2".

        Project2.ClassA Classa = new Project2.ClassA();
        Console.WriteLine(Classa.print);

but all i get are Error messages .

so can anyone please give a step by step explanation of EXACTLY why I need to do ?

like image 885
13driver Avatar asked Jul 08 '12 12:07

13driver


People also ask

How do you call a class from one project to another in C#?

Step 1: Make a reference from Project A to B. Step 2: Make Project B's Program. cs Public by adding the word "public" in front of "class Program". Step 3) Make a public method returnPath().

How do I reference another project in Eclipse?

Right click on Project1, then click on Properties. In the dialog that comes up, select Java Build Path, and then click on the Projects tab. There, add Project2 to the build path. If Project1 is a web app, you need to make sure your Deployment Assembly (same Properties UI) has Project2 there as well.


1 Answers

Follow these instructions:

  1. In the Solutions Explorer, right click on the project that you need to refer from.

  2. Select "Add Reference". (latter versions i.e. beyond 2015; not exactly sure though; it should be "Add->Reference". Right click on References and select Add Reference also will do.)

  3. Reference Manager - ProjectName dialog will appear.

  4. In the left pane, expand Projects menu. That will populate a list of existing projects in the middle of the dialog.

  5. Tick the checkbox before each project that you need to refer to.

  6. Press OK.

Once done, you can use all the public and protected (given you are inheriting from an existing one) in the project that you have referred to. Make sure you add using NameSpace.Class on the imports list.

like image 120
Khalid Avatar answered Nov 09 '22 21:11

Khalid