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#

hamad Al Ali
hamad Al Ali
3,893 Points

In Map.cs, shouldn't Point be instantiated in order to access its attributes?

Hello, would appreciate your help on the below !

In Game.cs, we instantiated map >> Map map = new Map(8, 5) << in order to access its attributes (Width and Height). With this logic in mind, we should also instantiate Point, in Map.cs under the onMap method, in order to access its attributes (X & Y), however this did not happen.

Is my understanding of instantiation incorrect ? What am I missing here?

Thanks a lot! :)

2 Answers

Steven Parker
Steven Parker
231,122 Points

The "point" is an argument passed to OnMap.

So it would not be instantiated inside the method, since it must already have been instantiated to be passed in as the argument.

In future questions, be sure to provide a link to the course page you are working with.

hamad Al Ali
hamad Al Ali
3,893 Points

Hi Steven,

Thanks for your quick response.

This makes sense, however point wasn't instantiated anywhere. Code compiles and runs without errors. Here's the link to the video.

https://teamtreehouse.com/library/c-objects/methods/methods

Steven Parker
Steven Parker
231,122 Points

The points are intantiated in Game.cs, right before they are passed to OnMap:

game.cs
            Point point = new Point(4, 2);    // point is instantiated here
            bool isOnMap = map.OnMap(point);  // and is then passed to OnMap
hamad Al Ali
hamad Al Ali
3,893 Points

Thanks a lot Steven! This brings me to the next question, since we have multiple .cs files and our "main" function in game .cs at what order are different objects/classes called? does it all start from the "main" function?

Steven Parker
Steven Parker
231,122 Points

That is correct. The system calls the Main() method, and everything the program does is a result of the code there (and called from there).

hamad Al Ali
hamad Al Ali
3,893 Points

Gotcha. Thanks a lot man!