mcmcom
June 11th, 2003, 11:18 AM
More problems with this FriendList Class.
I figured out how to implement the IComparer interface to
provide a default sort on my array of objects. Now I am asked
to provide a string input and get results from the matching array item.
I have to go like this:
1. enter the name
2. display phone number and b day that matches that name.
BELOW IS THE IComparable methid that makes it sort. You can
see it compares the string Name!
// Implement IComparable CompareTo to provide default sort order.
// THIS SORT WORKS!!!
int IComparable.CompareTo(object obj)
{
Friends f=(Friends)obj;
return String.Compare(this.Name,f.Name);
}
But what do I use to compare the input to this.
I have so far:
Console.WriteLine("Enter the Name:");
input = Console.ReadLine();
eString = Convert.ToString(input);
Now what do I do. Would a binary search work? Or do I have
to call the Comparer somehow. PLEASE HELP!!! Thanks
I figured out how to implement the IComparer interface to
provide a default sort on my array of objects. Now I am asked
to provide a string input and get results from the matching array item.
I have to go like this:
1. enter the name
2. display phone number and b day that matches that name.
BELOW IS THE IComparable methid that makes it sort. You can
see it compares the string Name!
// Implement IComparable CompareTo to provide default sort order.
// THIS SORT WORKS!!!
int IComparable.CompareTo(object obj)
{
Friends f=(Friends)obj;
return String.Compare(this.Name,f.Name);
}
But what do I use to compare the input to this.
I have so far:
Console.WriteLine("Enter the Name:");
input = Console.ReadLine();
eString = Convert.ToString(input);
Now what do I do. Would a binary search work? Or do I have
to call the Comparer somehow. PLEASE HELP!!! Thanks