Solved

Using IEqualityComparer

Posted on 2009-07-09
2
428 Views
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;
                }
                else
                {
                    return false;
                }
            }
        }
    }
}

Open in new window

0
Comment
Question by:AstroGuy
2 Comments
 
LVL 4

Accepted Solution

by:
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.
0
 

Author Closing Comment

by:AstroGuy
ID: 31601658
Workrd like a charm
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Exit the loop 4 42
Best resource to learn entity framework 2 33
jQuery - following an example but can I save data server side? 20 50
C# LINQ ForEach() question 6 28
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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