|
-
November 1st, 2008, 03:27 PM
#1
Arraylist,IComparer
Hai Frnds, Iam beginner to dotnet. Please explain mr below in detail.
class User : IComparable {
private string firstName;
private string lastName;
public User(string fn, string ln) {
this.firstName=fn;
this.lastName=ln;
}
//I did not understand this below method at all..please be clear here
public int CompareTo(object obj) {
User u=(User)obj;
if (this.lastName==u.lastName) {
return this.firstName.CompareTo(u.firstName);
} else {
return this.lastName.CompareTo(u.lastName);
}
}
public override string ToString() {
return lastName+" "+firstName;
}
Thanking you in advance
-
November 1st, 2008, 03:33 PM
#2
Re: Arraylist,IComparer
Code:
//I did not understand this below method at all..please be clear here
public int CompareTo(object obj) {
It simply compares the last and first names.....
What specifically to you not understand???
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
November 1st, 2008, 07:40 PM
#3
Re: Arraylist,IComparer
Thanks a lot frnd, If you dont mind could you please explain in detail How does IComparer and Icomparable works with arraylist??
-
November 1st, 2008, 08:04 PM
#4
Re: Arraylist,IComparer
ICompareble is a simple interface which defines how to compare two objects.
ArrayList (when used with comparable objects), can be sorted by using this interface.
I still dont understand what you are SPECIFICALLY looking for....
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|