exam questions

Exam 70-483 All Questions

View all questions & answers for the 70-483 exam

Exam 70-483 topic 2 question 120 discussion

Actual exam question from Microsoft's 70-483
Question #: 120
Topic #: 2
[All 70-483 Questions]

DRAG DROP -
You are developing a class named Temperature.
You need to ensure that collections of Temperature objects are sortable.
You have the following code:

Which code segments should you include in Target 1, Target 2 and Target 3 to complete the code? (To answer, drag the appropriate code segments to the correct targets in the answer area. 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.)
Select and Place:

Show Suggested Answer Hide Answer
Suggested Answer:
Note:
Target 1:
The role of IComparable is to provide a method of comparing two objects of a particular type. This is necessary if you want to provide any ordering capability for your object.
Incorrect: The role of IComparer is to provide additional comparison mechanisms. For example, you may want to provide ordering of your class on several fields or properties, ascending and descending order on the same field, or both.
Target 2, Target 3:
Example:
// Implement IComparable CompareTo method - provide default sort order. int IComparable.CompareTo(object obj)
{
car c=(car)obj;
return String.Compare(this.make,c.make);
}
Reference: How to use the IComparable and IComparer interfaces in Visual C# https://support.microsoft.com/en-us/kb/320727

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
supersunny
Highly Voted 5 years, 10 months ago
public class Temperature:IComparable, CompareTo, this.Fahrenheit.CompareTo(otherTemperature.Fahrenheit)
upvoted 61 times
BitMan20
5 years, 5 months ago
this. example https://docs.microsoft.com/en-us/dotnet/api/system.icomparable.compareto?view=netframework-4.8#examples
upvoted 13 times
...
...
supersunnyfan
Highly Voted 5 years, 4 months ago
supersunny is correct
upvoted 20 times
...
HgstExam
Most Recent 4 years, 9 months ago
Last option is wrong, should be: this.Fahrenheit.CompareTo(otherTemperature.Fahrenheit); when we call the CompareTo method we are comparing the currrent class to the other class not the other way around.
upvoted 6 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...