Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace EgoDelegate
- {
- public static class HashSetExtension
- {
- public static void DisplaySet(this HashSet<int> set)
- {
- Console.Write("{");
- foreach( int i in set)
- {
- Console.Write(" {0}", i);
- }
- Console.WriteLine(" }");
- }
- public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
- {
- foreach (T element in source)
- {
- action(element);
- }
- }
- }
- class Damn
- {
- static void Main()
- {
- HashSet<int> evenNumbers = new HashSet<int>();
- HashSet<int> oddNumbers = new HashSet<int>();
- for (int i = 0; i < 5; i++)
- {
- evenNumbers.Add(i * 2);
- oddNumbers.Add((i * 2) + 1);
- }
- evenNumbers.DisplaySet();
- oddNumbers.DisplaySet();
- // union of two sets
- HashSet<int> uniformedSet = new HashSet<int>(evenNumbers);
- uniformedSet.UnionWith(oddNumbers);
- uniformedSet.ForEach(x => Console.Write(x + " "));
- }
- }
- }
Add Comment
Please, Sign In to add comment