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#

Why we need add * -1?

Can anyone explain it? I don't understand why we need add * -1.

Update: https://teamtreehouse.com/library/serializing-to-a-file sr guys, my question for this video.

Steven Parker
Steven Parker
231,122 Points

I'm not sure what you're asking about. If it's something from a video, could you provide a link to the video and an approximate time index? And if it's a quiz or challenge, could you provide a link to that page and show the complete code you're working with?

David Tomko
David Tomko
7,744 Points

I actually just learned this at work the other day. Basically the compareTo returns a 1 if the thing being compared is less than what it's compared to. It returns a 0 if they're equal, and a -1 if the thing being compared is more than what it's compared to. So multiplying by -1 will order the results in descending order. Where normally it is in ascending order.

David Tomko
David Tomko
7,744 Points

I actually just learned this at work the other day. Basically the compareTo returns a 1 if the thing being compared is less than what it's compared to. It returns a 0 if they're equal, and a -1 if the thing being compared is more than what it's compared to. So multiplying by -1 will order the results in descending order. Where normally it is in ascending order.

Steven Parker
Steven Parker
231,122 Points

David Tomko — Did you realize you just added the same comment as you put here last month? :confused: