C# HashSet Count

Description

HashSet Count gets the number of elements that are contained in a set.

Syntax

HashSet.Count has the following syntax.


public int Count { get; }

Example


using System;//from  w w  w .  j ava2s.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.Count);
  }
}

The code above generates the following result.





















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




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack