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 trialhamad Al Ali
3,893 PointsIn 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
231,172 PointsThe "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
3,893 PointsGotcha. Thanks a lot man!
hamad Al Ali
3,893 Pointshamad Al Ali
3,893 PointsHi 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
231,172 PointsSteven Parker
231,172 PointsThe points are intantiated in Game.cs, right before they are passed to OnMap:
hamad Al Ali
3,893 Pointshamad Al Ali
3,893 PointsThanks 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
231,172 PointsSteven Parker
231,172 PointsThat is correct. The system calls the Main() method, and everything the program does is a result of the code there (and called from there).