TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Maha
NA
0
327.9k
IComparable
Aug 21 2012 1:23 PM
Program in the following website is altered (http://www.c-sharpcorner.com/UploadFile/prasadh/IComparablePSD12062005010125AM/IComparablePSD.aspx)
Whether it is < or > output is same. Please explain the reason. Problem is highlighted.
using System;
class Employee : IComparable
{
private int Id;
public Employee(int id)
{
this.Id = id;
}
public int CompareTo(object obj)
{
Employee temp = (Employee)obj;
if (this.Id
<
temp.Id)
//if(this.Id
>
temp.Id)
return 1;
else
if (temp.Id == this.Id)
return 0;
else
return -1;
}
public static void Main()
{
Employee[] employees = new Employee[5];
Console.WriteLine("Before Sort:");
for (int i = 0; i < employees.Length; i++)
{
employees[i] = new Employee(5 - i);
Console.Write("{0}, ", 5-i);
}
Console.WriteLine("\n");
Array.Sort(employees);
Console.WriteLine("After Sort:");
for (int i = 0; i < employees.Length; i++)
{
Console.Write("{0}, ", 5 - i);
}
Console.WriteLine();
Console.ReadKey();
}
}
/*
Before Sort:
5, 4, 3, 2, 1,
After Sort:
5, 4, 3, 2, 1,
*/
Reply
Answers (
8
)
Why does the return statement have to be t.x; ?
"Enable one form form other" Enable form2 from form1