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
326.2k
Different ways in implementing CompareTo()
Aug 25 2012 1:02 PM
Following are the three different ways of implementing CompareTo(). Could you tell me please which is the most acceptable to programmers and why?
1)
public int CompareTo(Object o)
{
int returnVal;
Employee temp = (Employee)o;
if (this.idNumber > temp.idNumber)
returnVal = 1;
else
if (this.idNumber < temp.idNumber)
returnVal = -1;
else
returnVal = 0;
return returnVal;
}
2)
public int CompareTo(Object o)
{
if (o is Employee)
{
Employee temp = (Employee)o;
return temp.idNumber.CompareTo(this.idNumber);
}
else
throw new ArgumentException("Object is not a Employee.");
}
3)
public int CompareTo(Object o)
{
Employee temp = (Employee)o;
return (this.idNumber - temp.idNumber);
}
Reply
Answers (
2
)
how to Find string in txt file and delete line with this string
Shortest path in an undirected and complete graph