Convert HashSet To Array - CSharp System

CSharp examples for System:Array Convert

Description

Convert HashSet To Array

Demo Code


using System.Reflection;
using System.Linq;
using System.Collections.Generic;
using System;//  w  w w . ja v a 2  s.c  om

public class Main{
        /// <summary>
      /// For unexplainable reasons, HashSet's ToArray method is internal
      /// </summary>
      public static T[] MakeArray<T>(this HashSet<T> set)
      {
         var arr = new T[set.Count];
         var i = 0;
         foreach (var item in set)
         {
            arr[i++] = item;
         }
         return arr;
      }
}

Related Tutorials