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 2

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


Kaabi

Kaabi

For example, if you are creating an Order class that has a DateTime Created property that you want to sort on, you can implement IComparable on the Order class and compare the Created dates of both orders
Implementing the IComparable interface

class Order : IComparable
{
public DateTime Created
{get; set; }
public int CompareTo(object obj)
{
if (obj == null) return 1;
Order o = obj as Order;
if (o == null)
{
throw new ArgumentException(“Object is not an Order”);
}
return this.Created.CompareTo(o.Created); }