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, I have a rather curious problem. Im following along with the C# objects course and entering the code into visual studio 2015 on my local dev environment.

Map.cs :
namespace TreehouseDefense 
{
    public class Map
    {
        public int Width;
        private int height;

    }
}

Game.cs:
namespace TreehouseDefense
{
    class Game 
    {
        public static void Main()
        {
            Map map = new Map();
            map.Width = 10;
        }
    }

For some reason, Intellisence is not showing me the Map object and map.Width also doesn't show up in my intellisence.

Anybody have a tip?

2 Answers

James Churchill
STAFF
James Churchill
Treehouse Teacher

Chris,

Did you create a new project using the "New Project" dialog (from the top menu it's "File > New > Project")?

For two C# files to be "aware" of each other in Visual Studio, they need to be part of the same project. You can verify the existence of a project by looking for a .csproj file in the folder that contains your .cs files.

I hope this helps resolve your issue. If it doesn't, let me know, and we'll try something else :)

Thanks ~James

This helped a little. I now have a visual studio solution that has 2 projects. 1) A TowerDefence project that contains all the classes referenced to in the C# objects tower defence game. 2) A second project that is a console project so I can run instances of classes from the 1st project. I have a reference from project 1 in project 2, but I can't see the classes from project 1 in the project 2 console.

(I also have a using statement to use the project 1 in the project 2)