-
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
-
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???
-
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??
-
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.... :confused: :confused: :confused: