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 Loops and Final Touches Magic Numbers and Constants

Ilya Sikharulidze
PLUS
Ilya Sikharulidze
Courses Plus Student 1,073 Points

Error in MapLocation class

public bool InRangeOf(MapLocation location, int range) { return DistanceTo(location.X, location.Y) <= range;

        }

In visual studio 2019 it says that: "The modifier 'public' is not valid for this term" Can someone explain? It seems to work for him in the video though

2 Answers

Steven Parker
Steven Parker
231,268 Points

Sometimes the compiler doesn't notice an error until it gets to the following line. I'd look at the previous line, it may be something as simple as a missing semicolon.

If that's not it, please show more of the code (perhaps the entire module).

I think you're missing a bit of code, which overloads the DistanceTo method, with a single point. This is passed into the original method:

public int DistanceTo(Point point)
        {
            return DistanceTo(point.X, point.Y);
        }