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 Methods Overloading Methods

Overloaded methods return type

"Overloaded methods in the same class must return the same type" - said Jeremy Is this true?

I overload DistanceTo method with Point type parameter, return double and there is no compiler errors. Also in the Math class there are plenty of methods that are overloaded and return different types.

2 Answers

Steven Parker
Steven Parker
231,198 Points

:point_right: I think you've discovered a bug in the lesson.

I've used C# for years and I'm also not aware of any such restriction. Perhaps he meant to say that overloaded members may not differ by only the return type.

:beetle: You might want to report this as a bug on the Support page.

Jeremy McLain
Jeremy McLain
Treehouse Guest Teacher

Steven's correct. I'll have that line removed. Thanks for catching that Jacek Gałka! I'll get you an exterminator badge.

It's my pleasure. ?