Solved

Using IEqualityComparer

Posted on 2009-07-09
2
436 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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