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:

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

  1. Kaabi says:

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




    0



    0

Leave a Reply