473,624 Members | 2,584 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SortedList case-insensitive key comparisons

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
Nov 16 '05 #1
3 2812
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 CaseInsensitive Comparer(x,y));
}
}
--- here how I used it ---
string[] urArray = new string[]{"Come","age"," Apple","Go"};
IComparer mc = new MyComparer();

Array.Sort(urAr ray, mc);

I just did it few day ago.

Cheers,
Kids

"Michael C" <mi******@nospa m.org> wrote in message
news:jN******** ********@news4. srv.hcvlny.cv.n et...
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

Nov 16 '05 #2
I'm using a SortedList and I need to sort by Key value.

Thanks,
Michael C., MCDBA

"kids_pro" <ki******@yahoo .com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
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 CaseInsensitive Comparer(x,y));
}
}
--- here how I used it ---
string[] urArray = new string[]{"Come","age"," Apple","Go"};
IComparer mc = new MyComparer();

Array.Sort(urAr ray, mc);

I just did it few day ago.

Cheers,
Kids

"Michael C" <mi******@nospa m.org> wrote in message
news:jN******** ********@news4. srv.hcvlny.cv.n et...
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


Nov 16 '05 #3
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 CaseInsensitive Comparer(a.Key, b.Key));
}
}
"Michael C" <mi******@nospa m.org> wrote in message
news:V7******** **********@news 4.srv.hcvlny.cv .net...
I'm using a SortedList and I need to sort by Key value.

Thanks,
Michael C., MCDBA

"kids_pro" <ki******@yahoo .com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
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 CaseInsensitive Comparer(x,y));
}
}
--- here how I used it ---
string[] urArray = new string[]{"Come","age"," Apple","Go"};
IComparer mc = new MyComparer();

Array.Sort(urAr ray, mc);

I just did it few day ago.

Cheers,
Kids

"Michael C" <mi******@nospa m.org> wrote in message
news:jN******** ********@news4. srv.hcvlny.cv.n et...
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



Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2761
by: Zeng | last post by:
Would someone know why SortedList doesn't work for these two keys? System.Collections.SortedList.Add(Object key, Object value) +221 My code looks something like below, the Guid.NewGuid().ToString() is appended to make sure the key is unique in case of duplicated data.
8
3119
by: Dennis C. Drumm | last post by:
I have a class derived from a SortedList called SystemList that contains a list of objects indexed with a string value. The definition of the objects contained in the SortedList have a boolean field and an event that is fired if the boolean field value changes. The derived SortedList class has an override for the Add method. The Add method adds an event handler for the object's event for each new item added to the list. In the...
2
9132
by: Sean | last post by:
How does one bind a SortedList to anything. If it cant be done why would anyone ever even use a sortedlist? We are currently (via business objects that use interfaces etc) binding gridviews to List<T> type with zero problem which was an upgrade from our previous methodology of doing the exact same thing with Arraylists. However now using SortedList it doesnt work becuase it doesnt have an index but rather a "key" which in our case is...
2
2040
by: Prez | last post by:
I started writing .net code yesterday and I am grasping it well enough. I have a few questions about SortedLists. I am using managed C++ if that makes any difference. Of the examples I have seen it looks like the Sorted List does not use the ^ while other variables do use the ^. I have used the SortedList with the ^ and gcnew and it seems to work fine. So the question is...
4
10117
by: SHEBERT | last post by:
Here is an example of a SortedList that works as a datasource to the ComboBox and a generic SortedList<that does not works as a datasource to the ComboBox. Why? If I use List and generic List<>, both works. private void Form1_Load(object sender, EventArgs e) { System.Collections.SortedList QA1 = new System.Collections.SortedList();
4
5068
by: aeshiels | last post by:
Hello, I have a SortedList defined as... SortedList<CUser, CUseruserList = new SortedList<CUser, CUser>(); ....and which to copy it to another sorted list SortedList<CUser, CUseruserList2 = new SortedList<CUser,
6
1536
by: Antonio Paglia | last post by:
Hello. I have tried to insert this items into a SortedList. dic = New SortedList dic.Add("<<", "<<") dic.Add("==", "==") dic.Add(">>", ">>") dic.Add("@@", "@@") dic.Add("??", "??") Debugging this peace of code I have notice that '??' appears as first item,
1
3897
by: raylopez99 | last post by:
I seem to get name collision between the Generic collection SortedList and C++.NET Framework collection SortedList. How to resolve? Here are the libraries that seem to clash: System::Collections::SortedList, System::Collections::Generic::SortedList, using namespace System::Collections; using namespace System::Collections::Generic; Below is a working version of the generic template SortedList, which
6
2507
by: n3tx | last post by:
Hi! I have a problem with sortedlist, i guess i dont understand how it works. I have a method called GetPublishingPlaces that returns an IList<PublishingPlace> (ex. contains 11 rows) I want to sort the list in different orders, I dont know if this is something that SortedList do ? i have a property in the PublishingPlace called Place, name, exposure
3
4469
dcharnigo
by: dcharnigo | last post by:
I thought I would be tricky and force the SortedList to not sort using a custom IComparer, I used the following code, but when the list is sorting using the custom sort the accessors become unusable and throw exceptions. I have since discovered that the accessors use the IComparer to find things and since it is set at -1 it gets a null return value, however the foreach loops dont use it. I must preserve the insert order, I don't want the...
0
8179
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8685
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8633
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8348
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2613
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1797
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.