Converting the combined set to a list - CSharp Collection

CSharp examples for Collection:List

Description

Converting the combined set to a list

Demo Code

using System;/*w  w w .  j  av  a2s .  c o m*/
using System.Collections.Generic;
class Program
{
   static void Main(string[] args)
   {
      List<string> colors = new List<string> { "red", "orange", "yellow" };
      string[] moreColors = { "orange", "yellow", "green", "blue", "violet" };
      HashSet<string> combined = new HashSet<string>(colors);
      Console.WriteLine("\nConverting the combined set to a list:");
      // Initialize a new List from combined.
      List<string> spectrum = new List<string>(combined);
      foreach(string color in spectrum)
      {
         Console.WriteLine("{0}", color);
      }
   }
}

Result


Related Tutorials