PrepAway - Latest Free Exam Questions & Answers

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.)

PrepAway - Latest Free Exam Questions & Answers

Answer:

4 Comments on “How should you complete the relevant code segment?

  1. Serge says:

    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);




    1



    0
    1. Serge says:

      oops rushed myself

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

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




      0



      0
      1. Artem says:

        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…




        0



        1

Leave a Reply