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 Encapsulation and Arrays Encapsulation

Tomasz Halaczkiewicz
Tomasz Halaczkiewicz
21,845 Points

new MapLocation(0, 2, map)

new MapLocation(0, 2, map) What does "map" at the end of that line stand for? How does it work ? Please help Im confused

2 Answers

Steven Parker
Steven Parker
231,275 Points

The map variable contains a newly-created map object.

In the code above the line you quoted, there's another line with this:

        Map map = new Map(8, 5);

So that map object is being passed as one of the arguments to the constructor of MapLocation. That constructor uses the provided map to confirm that the location coordinates are within the map boundaries. Since the location is (0,2) and the map is 8x5, it should be fine.

Tomasz Halaczkiewicz
Tomasz Halaczkiewicz
21,845 Points

Thanks for your answer Steven! I'm still confused though. Since MapLocation constructor takes 2 int arguments shoudn't we pass just that ?

    class MapLocation : Point
    {
        public MapLocation(int x, int y) : base(x, y)
        {

        }
    }

It would make sense if we passed x, y and Point object but having "map" as third argument?

Steven Parker
Steven Parker
231,275 Points

This program evolves as the course progresses, the original definition for MapLocation that you show here takes only 2 arguments, but later in the course it is expanded to take a Map as a third argument which is used to validate the other 2.

The calls in this video are using that new format. Perhaps you skipped an earlier video, or part of one, where that change was made?

Tomasz Halaczkiewicz
Tomasz Halaczkiewicz
21,845 Points

Well I must have missed that somehow. Now it makes sense. Cheers Steven!