SortedList case-insensitive key comparisons

  • Thread starter Thread starter Michael C
  • Start date Start date
M

Michael C

Hi all,

I'm using a SortedList to store data, and want the keys to be compared in
case insensitive order, so that

mySList["a"]

is the same as

mySList["A"]

I've run across the IComparable interface, but not sure how to implement.
Anyone know where I can find more info and samples?

Thanks,
Michael C., MCDBA
 
I think you should just use normal Array and then implement IComparer
interface
There is a sample implementation in MSDN
---- here how they implment it ----
public class MyComparer: IComparer{
public int Comparer(object x, object y){
return(new CaseInsensitiveComparer(x,y));
}
}
--- here how I used it ---
string[] urArray = new string[]{"Come","age","Apple","Go"};
IComparer mc = new MyComparer();

Array.Sort(urArray, mc);

I just did it few day ago.

Cheers,
Kids
 
I'm using a SortedList and I need to sort by Key value.

Thanks,
Michael C., MCDBA

kids_pro said:
I think you should just use normal Array and then implement IComparer
interface
There is a sample implementation in MSDN
---- here how they implment it ----
public class MyComparer: IComparer{
public int Comparer(object x, object y){
return(new CaseInsensitiveComparer(x,y));
}
}
--- here how I used it ---
string[] urArray = new string[]{"Come","age","Apple","Go"};
IComparer mc = new MyComparer();

Array.Sort(urArray, mc);

I just did it few day ago.

Cheers,
Kids



Michael C said:
Hi all,

I'm using a SortedList to store data, and want the keys to be compared in
case insensitive order, so that

mySList["a"]

is the same as

mySList["A"]

I've run across the IComparable interface, but not sure how to implement.
Anyone know where I can find more info and samples?

Thanks,
Michael C., MCDBA
 
Hmm try this way I haven't test it yet

public class MyComparer: IComparer{
public int Comparer(object x, object y){
SortedList a = (SortedList)x;
SortedList b = (SortedList)y;

return(new CaseInsensitiveComparer(a.Key,b.Key));
}
}


Michael C said:
I'm using a SortedList and I need to sort by Key value.

Thanks,
Michael C., MCDBA

kids_pro said:
I think you should just use normal Array and then implement IComparer
interface
There is a sample implementation in MSDN
---- here how they implment it ----
public class MyComparer: IComparer{
public int Comparer(object x, object y){
return(new CaseInsensitiveComparer(x,y));
}
}
--- here how I used it ---
string[] urArray = new string[]{"Come","age","Apple","Go"};
IComparer mc = new MyComparer();

Array.Sort(urArray, mc);

I just did it few day ago.

Cheers,
Kids



Michael C said:
Hi all,

I'm using a SortedList to store data, and want the keys to be compared in
case insensitive order, so that

mySList["a"]

is the same as

mySList["A"]

I've run across the IComparable interface, but not sure how to implement.
Anyone know where I can find more info and samples?

Thanks,
Michael C., MCDBA
 
Back
Top