C# HashSet Comparer

Description

HashSet Comparer gets the IEqualityComparer object that is used to determine equality for the values in the set.

Syntax

HashSet.Comparer has the following syntax.


public IEqualityComparer<T> Comparer { get; }

Example


using System;// w  ww.ja  va2s.  co m
using System.Collections.Generic;

public class MainClass{
  public static void Main(String[] argv){  
    HashSet<int> evenNumbers = new HashSet<int>();
    for (int i = 0; i < 5; i++)
    {
        evenNumbers.Add(i * 2);
    }
    Console.WriteLine(evenNumbers.Comparer);
  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections.Generic »




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack