Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8450313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:56:11+00:00 2026-06-10T10:56:11+00:00

Tried following the documentation and I cannot make it work. Have a KeyedCollection with

  • 0

Tried following the documentation and I cannot make it work. Have a KeyedCollection with the key string.

How to make the string key case insensitive in a KeyedCollection?

On a Dictionary can just pass StringComparer.OrdinalIgnoreCase in the ctor.

private static WordDefKeyed wordDefKeyed = new WordDefKeyed(StringComparer.OrdinalIgnoreCase);   // this fails

public class WordDefKeyed : KeyedCollection<string, WordDef>
{
        // The parameterless constructor of the base class creates a 
        // KeyedCollection with an internal dictionary. For this code 
        // example, no other constructors are exposed.
        //
        public WordDefKeyed() : base() { }

        public WordDefKeyed(IEqualityComparer<string> comparer)
            : base(comparer)
        {
            // what do I do here???????
        }

        // This is the only method that absolutely must be overridden,
        // because without it the KeyedCollection cannot extract the
        // keys from the items. The input parameter type is the 
        // second generic type argument, in this case OrderItem, and 
        // the return value type is the first generic type argument,
        // in this case int.
        //
        protected override string GetKeyForItem(WordDef item)
        {
            // In this example, the key is the part number.
            return item.Word;
        }
}

private static Dictionary<string, int> stemDef = new Dictionary<string, int(StringComparer.OrdinalIgnoreCase);   // this works this is what I want for KeyedCollection
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:56:13+00:00Added an answer on June 10, 2026 at 10:56 am

    If you want your type WordDefKeyed to be case-insensitive by default, then your default, parameterless constructor should pass an IEqualityComparer<string> instance to it, like so:

    public WordDefKeyed() : base(StringComparer.OrdinalIgnoreCase) { }
    

    The StringComparer class has some default IEqualityComparer<T> implementations that are commonly used depending on the type of data you are storing:

    • StringComparer.Ordinal and StringComparer.OrdinalIgnoreCase – Used when you’re using machine-readable strings, not strings that are entered or displayed to the user.

    • StringComparer.InvariantCulture and StringComparer.CultureInvariantIgnoreCase – Used when you’re using strings that won’t be shown to the UI, but are sensitive to culture and may be the same across cultures.

    • StringComparer.CurrentCulture and StringComparer.CurrentCultureIgnoreCase – Use for strings that are specific to the current culture, such as when you’re gathering user input.

    If you need a StringComparer for a culture other than the one that is the current culture, then you can call the static Create method to create a StringComparer for a specific CultureInfo.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried following the instruction s but can't get the plugin to work, the
I tried following the following example to make an HTTP link in my TextView
I tried following the README file in Ruby 1.9.1 but I can't compile it
I have tried following queries to get my facebook fan page insights data SELECT
For example, I tried following example from documentation : =TEXT(WEEKDAY([Column1]), dddd) But it won't
I have tried to run the following code, as a proof of concept, and
How do I achieve the following in CMake (using version 2.8.5)? I have documentation
I have following web-fragment.xml in a jar file, under META-INF/ It seems I cannot
Tried following the instructions here: How to use Google app engine with my own
I tried following the gradle manual with their example like this but copyJars is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.