How should you complete the relevant code segment?

DRAG DROP
You are developing a class named Temperature.
You need to ensure that collections of Temperature objects are sortable.
How should you complete the relevant code segment? (To answer, drag the appropriate code
segments to the correct locations in the answer are
a. Each code segment may be used once, more than once, or not at all. You may need to drag the
split bar between panes or scroll to view content.)

DRAG DROP
You are developing a class named Temperature.
You need to ensure that collections of Temperature objects are sortable.
How should you complete the relevant code segment? (To answer, drag the appropriate code
segments to the correct locations in the answer are
a. Each code segment may be used once, more than once, or not at all. You may need to drag the
split bar between panes or scroll to view content.)

Answer:



Leave a Reply 4

Your email address will not be published. Required fields are marked *


Serge

Serge

it says: “You need to ensure that collections of Temperature objects are sortable.”, but nothing about how to sort (ascending or descending).

so if ascending then
return otherTemperature.Fahrenheit.CompareTo(this.Fahrenheit);

if descending then
return this.Fahrenheit.CompareTo(otherTempereature.Fahrenheit);

Serge

Serge

oops rushed myself

Ascending:
___________return this.Fahrenheit.CompareTo(otherTempereature.Fahrenheit);

Descending:
___________return otherTemperature.Fahrenheit.CompareTo(this.Fahrenheit);

Artem

Artem

You should always use ascending in CompareTo().
If you use “return otherTemperature.Fahrenheit.CompareTo(this.Fahrenheit)” then code
temperaturesList.OrderByDescending(x => x); sorts collection ascending. If this is what you want, can do this…