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 ?
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().
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.
Follow these instructions:
In the Solutions Explorer, right click on the project that you need to refer from.
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.)
Reference Manager - ProjectName dialog will appear.
In the left pane, expand Projects menu. That will populate a list of existing projects in the middle of the dialog.
Tick the checkbox before each project that you need to refer to.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With