Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

C# objects and visual studio

Hello, Im trying to code in visual studio 2015 the tower defence game in the C# objects course. I have 2 projects in VS2015. 1 project is the class library with the classes, and the 2nd project is a console app where I can create objects from the class libraries. For some reason, I can't see the classes from the console project. Would somebody here be able to tell me why that is? I can easily send you the solution in Visual Studio if you require.

2 Answers

Hi there!

Okay so if I've got this correct, you have 1 solution with two projects in it, each project has one .cs file in it, and you want to be able to call between a file in one project and a file in another project?

So long as that's it, you just right click on the project of the console app, hover over Add and click Reference. In the windows that pops up click on "Projects" and tick the project you want to be able to access - the library project.

This creates a one way link (the library class project can't see the console app project but the console app project can see the class library project) for the compiler to be able to find the files you're talking about. By default the compiler will only look inside the project, so you're just giving it a new path to look down.

After that, it's just a case of using them like normal - type the namespace of the class library followed by the class you want, or if you want all of them, add the namespace with a using to the top of any files that need them

Hope it helps :)

Hello, yeah that's exactly what I've tried and still I can see the class libraries from the console project. This might be a big ask, but if I sent you the solution, would you be able to show me my mistake?