Using IEqualityComparer

Posted on 2009-07-09
Last Modified: 2012-05-07
Code generates 2 errors
Error      1      Using the generic type 'System.Collections.Generic.IEqualityComparer<T>' requires '1' type arguments      C:\Documents and Settings\xxxx\My Documents\Visual Studio 2005\Projects\HashInsensitiveComparer216\HashInsensitiveComparer216\Program.cs

Error      2      The type or namespace name 'CaseInsensitiveComparer' could not be found (are you missing a using directive or an assembly reference?)      C:\Documents and Settings\xxxx\My Documents\Visual Studio 2005\Projects\HashInsensitiveComparer216\HashInsensitiveComparer216\Program.cs
using System;

using System.Collections.Generic;

using System.Text;

using System.Globalization;

namespace HashInsensitiveComparer216


    class Program


        static void Main(string[] args)


            Hashtable dehash = new Hashtable(new InsensitiveComparer());

            dehash["First"] = "1st";

            dehash["Second"] = "2nd"; 

            dehash["Third"] = "3rd"; 

            dehash["Fourth"] = "4th"; 

            dehash["fourth"] = "5th";

            Console.WriteLine(dehash.Count); // 4 


        public class InsensitiveComparer : IEqualityComparer


            CaseInsensitiveComparer _comparer = new CaseInsensitiveComparer();

            public int GetHashCode(object obj)


                return obj.ToString().ToLowerInvariant().GetHashCode();


            public new bool Equals(object x, object y)


                if (_comparer.Compare(x, y) == 0)


                    return true;




                    return false;






Open in new window

Question by:AstroGuy

Accepted Solution

Woodz earned 500 total points
ID: 24814869
You are using the namespace System.Collections.Generic, which contains the generic IEqualityComparer<T> interface. It is complaining because you have not specified the generic type of this interface. If you intended to use the old, non-generic interface, change the using namespace to System.Collections.

Author Closing Comment

ID: 31601658
Workrd like a charm

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now