Wintellect Power Collections Libraryを使う Set編

Wintellect Power Collections Libraryは、Wintellect社がマイクロソフトから要請を受けてC++STLのコンテナクラスをCLRを利用する開発者にも提供するために開発された。

以下のサイトからダウンロードして無償で利用できる。
http://www.codeplex.com/PowerCollections



Wintellect Power Collections Libraryに含まれるジェネリックコレクションクラスは以下の通り。

BagList順序を保持しないTオブジェクトのコレクション。重複が許される。
Bag順序を保持しないTオブジェクトのコレクション。重複が許される。
OrderedBag順序を保持するオブジェクトのコレクション。重複が許される。
Set順序を保持しないTオブジェクトのコレクション。重複が許可されない。
OrderedSet順序を保持するTオブジェクトのコレクション。重複が許されない。
Deque両端待ち行列
OrderedDictionaryキーの順序を保持するディクショナリー。キーごとに値を1つ持てる。
MultiDictionaryキーに値を複数保持できるディクショナリー。キーは重複が許される。項目の順序は保持されない。
OrderedMultiDictionaryキーの順序を保持し、値を複数保持できるディクショナリー。順序が保持される。キーの重複が許可される。








Wintellect Power Collections LibraryのSetクラスを使う。

Setクラスには、以下のようなメソッドがある。

Add
AddMany
AsReadOnly
Clear
Clone
CloneContents
Contains
ConvertAll<(Of )>
CopyTo
CountWhere
Difference
DifferenceWith
Equals
Exists
FindAll
ForEach
GetEnumerator
GetHashCode
GetType
Intersection
IntersectionWith
IsDisjointFrom
IsEqualTo
IsProperSubsetOf
IsProperSupersetOf
IsSubsetOf
IsSupersetOf
Remove
RemoveAll
RemoveMany
SymmetricDifference
SymmetricDifferenceWith
ToArray
ToString
TrueForAll
TryGetItem
Union
UnionWith

  • Add
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s.Add(i);
            }
    
            foreach (Int32 i in s)
            {
                Console.WriteLine(i);
            }
        }
    }


  • AddMany
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Int32[] arr = new Int32[10];
            for (Int32 i = 0; i < arr.Length; i++)
            {
                arr[i] = i;
            }
    
            List<Int32> l = new List<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                l.Add(i + 10);
            }
    
            Set<Int32> s = new Set<Int32>();
            s.AddMany(l);
            s.AddMany(arr);
    
            foreach (Int32 i in s)
            {
                Console.WriteLine(i);
            }
        }
    }


  • AsReadOnly
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s.Add(i);
            }
    
            ICollection<Int32> col = s.AsReadOnly();
            foreach (Int32 i in col)
            {
                Console.WriteLine(i);
            }
        }
    }

  • Clear
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s.Add(i);
            }
    
            foreach (Int32 i in s)
            {
                Console.WriteLine(i);
            }
    
            s.Clear();
    
            Console.WriteLine("Count:{0}", s.Count);
        }
    }

  • Clone
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s.Add(i);
            }
    
            Set<Int32> cloneSet = s.Clone();
            foreach (Int32 i in cloneSet)
            {
                Console.WriteLine(i);
            }
        }
    }

  • CloneContents
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s.Add(i);
            }
    
            Set<Int32> deepClone = s.CloneContents();
            foreach (Int32 i in deepClone)
            {
                Console.WriteLine(i);
            }
        }
    }


  • Contains
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s.Add(i);
            }
    
            if (s.Contains(0))
            {
                Console.WriteLine("Contains 0");
            }
    
            if (!s.Contains(10))
            {
                Console.WriteLine("Not Contains 10");
            }
        }
    }

  • ConvertAll
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s.Add(i);
            }
    
            IEnumerable squares =
                s.ConvertAll<Int32>(delegate(Int32 n)
                {
                    return n * n;
                });
            foreach (Int32 i in squares)
            {
                Console.WriteLine(i);
            }
    
            IEnumerable<String> details =
                s.ConvertAll<String>(delegate(Int32 n)
                {
                    return String.Format("Set Element:{0}", n);
                });
            foreach (String detail in details)
            {
                Console.WriteLine(detail);
            }
        }
    }

  • CopyTo
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s.Add(i);
            }
    
            Int32[] arr = new Int32[s.Count];
            s.CopyTo(arr, 0);
    
            foreach (Int32 i in arr)
            {
                Console.WriteLine(i);
            }
        }
    }


  • CountWhere
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s.Add(i);
            }
    
            Int32 evens =
                s.CountWhere(delegate(Int32 n)
                {
                    return n % 2 == 0;
                });
    
            Console.WriteLine("Even Number Count:{0}", evens);
        }
    }


  • Difference
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s1 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s1.Add(i);
            }
    
            Set<Int32> s2 = new Set<Int32>();
            for (Int32 i = 0; i < 5; i++)
            {
                s2.Add(i);
            }
    
            Set<Int32> diff = s1.Difference(s2);
            foreach (Int32 i in diff)
            {
                Console.WriteLine(i);
            }
        }
    }


  • DifferenceWith
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s1 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s1.Add(i);
            }
    
            Set<Int32> s2 = new Set<Int32>();
            for (Int32 i = 0; i < 5; i++)
            {
                s2.Add(i);
            }
    
            s1.DifferenceWith(s2);
            foreach (Int32 i in s1)
            {
                Console.WriteLine(i);
            }
        }
    }


  • Equals
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s1 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s1.Add(i);
            }
    
            Set<Int32> s2 = new Set<Int32>();
            for (Int32 i = 0; i < 5; i++)
            {
                s2.Add(i);
            }
    
            if (s1.Equals(s2)) //Equivalent for reference
            {
                Console.WriteLine("s1 equal s2");
            }
            else
            {
                Console.WriteLine("s1 not equal s2");
            }
        }
    }


  • Exists
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s.Add(i);
            }
    
            Boolean ret =
                s.Exists(delegate(Int32 n)
                {
                    return n == 5 || n == 6;
                });
    
            Console.WriteLine("{0} 5 or 6",
                ret ? "Exists" : "Not Exists");
        }
    }

  • FindAll
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s.Add(i);
            }
    
            IEnumerable<Int32> evens =
                s.FindAll(delegate(Int32 n)
                {
                    return n % 2 == 0;
                });
    
            foreach (Int32 i in evens)
            {
                Console.WriteLine(i);
            }
        }
    }


  • ForEach
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s.Add(i);
            }
    
            s.ForEach(delegate(Int32 n)
            {
                Console.WriteLine("Set Element:{0}", n);
            });
        }
    }

  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s1 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s1.Add(i);
            }
    
            Set<Int32> s2 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s2.Add(i * 2);
            }
    
            Set<Int32> intersection = s1.Intersection(s2);
            intersection.ForEach(delegate(Int32 n)
            {
                Console.WriteLine(n);
            });
        }
    }

  • IntersectionWith
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s1 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s1.Add(i);
            }
    
            Set<Int32> s2 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s2.Add(i * 2);
            }
    
            s1.IntersectionWith(s2);
            s1.ForEach(delegate(Int32 n)
            {
                Console.WriteLine(n);
            });
        }
    }

  • IsDisjointFrom
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s1 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s1.Add(i);
            }
    
            Set<Int32> s2 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s2.Add(i * 2);
            }
    
            Set<Int32> s3 = new Set<Int32>();
            for (Int32 i = 100; i < 110; i++)
            {
                s3.Add(i);
            }
    
            Console.WriteLine(s1.IsDisjointFrom(s2));
            Console.WriteLine(s1.IsDisjointFrom(s3));
        }
    }

  • IsEqualTo
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s1 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s1.Add(i);
            }
    
            Set<Int32> s2 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s2.Add(i);
            }
    
            Set<Int32> s3 = new Set<Int32>();
            for (Int32 i = 0; i < 9; i++)
            {
                s3.Add(i);
            }
    
    
            if (s1.IsEqualTo(s2))
            {
                Console.WriteLine("s1 equal s2");
            }
            else
            {
                Console.WriteLine("s1 not equal s2");
            }
    
            if (s1.IsEqualTo(s3))
            {
                Console.WriteLine("s1 equal s3");
            }
            else
            {
                Console.WriteLine("s1 not equal s3");
            }
        }
    }

  • IsProperSubsetOf
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s1 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s1.Add(i);
            }
    
            Set<Int32> s2 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s2.Add(i);
            }
    
            Set<Int32> s3 = new Set<Int32>();
            for (Int32 i = 0; i < 9; i++)
            {
                s3.Add(i);
            }
    
            //////////////////////////////
            //
            if (s1.IsProperSubsetOf(s2))
            {
                Console.WriteLine("s1 is proper subset of s2");
            }
            else
            {
                Console.WriteLine("s1 is not proper subset of s2");
            }
    
            //////////////////////////////
            //
            if (s2.IsProperSubsetOf(s1))
            {
                Console.WriteLine("s2 is proper subset of s1");
            }
            else
            {
                Console.WriteLine("s2 is not proper subset of s1");
            }
    
            //////////////////////////////
            //
            if (s3.IsProperSubsetOf(s1))
            {
                Console.WriteLine("s3 is proper subset of s1");
            }
            else
            {
                Console.WriteLine("s3 is not proper subset of s1");
            }
        }
    }

  • IsProperSupersetOf
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s1 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s1.Add(i);
            }
    
            Set<Int32> s2 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s2.Add(i);
            }
    
            Set<Int32> s3 = new Set<Int32>();
            for (Int32 i = 0; i < 9; i++)
            {
                s3.Add(i);
            }
    
            //////////////////////////////
            //
            if (s1.IsProperSupersetOf(s2))
            {
                Console.WriteLine("s1 is proper superset of s2");
            }
            else
            {
                Console.WriteLine("s1 is not proper superset of s2");
            }
    
            //////////////////////////////
            //
            if (s2.IsProperSupersetOf(s1))
            {
                Console.WriteLine("s2 is proper superset of s1");
            }
            else
            {
                Console.WriteLine("s2 is not proper superset of s1");
            }
    
            //////////////////////////////
            //
            if (s1.IsProperSupersetOf(s3))
            {
                Console.WriteLine("s1 is proper superset of s3");
            }
            else
            {
                Console.WriteLine("s1 is not proper superset of s3");
            }
        }
    }

  • IsSubsetOf
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s1 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s1.Add(i);
            }
    
            Set<Int32> s2 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s2.Add(i);
            }
    
            Set<Int32> s3 = new Set<Int32>();
            for (Int32 i = 0; i < 9; i++)
            {
                s3.Add(i);
            }
    
            //////////////////////////////
            //
            if (s1.IsSubsetOf(s2))
            {
                Console.WriteLine("s1 is subset of s2");
            }
            else
            {
                Console.WriteLine("s1 is not subset of s2");
            }
    
            //////////////////////////////
            //
            if (s2.IsSubsetOf(s1))
            {
                Console.WriteLine("s2 is subset of s1");
            }
            else
            {
                Console.WriteLine("s2 is not subset of s1");
            }
    
            //////////////////////////////
            //
            if (s3.IsSubsetOf(s1))
            {
                Console.WriteLine("s3 is subset of s1");
            }
            else
            {
                Console.WriteLine("s3 is not subset of s1");
            }
    
            //////////////////////////////
            //
            if (s1.IsSubsetOf(s3))
            {
                Console.WriteLine("s1 is subset of s3");
            }
            else
            {
                Console.WriteLine("s1 is not subset of s3");
            }
        }
    }

  • IsSupersetOf
  • Set<Int32> s1 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s1.Add(i);
            }
    
            Set<Int32> s2 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s2.Add(i);
            }
    
            Set<Int32> s3 = new Set<Int32>();
            for (Int32 i = 0; i < 9; i++)
            {
                s3.Add(i);
            }
    
            //////////////////////////////
            //
            if (s1.IsSupersetOf(s2))
            {
                Console.WriteLine("s1 is superset of s2");
            }
            else
            {
                Console.WriteLine("s1 is not superset of s2");
            }
    
            //////////////////////////////
            //
            if (s2.IsSupersetOf(s1))
            {
                Console.WriteLine("s2 is superset of s1");
            }
            else
            {
                Console.WriteLine("s2 is not superset of s1");
            }
    
            //////////////////////////////
            //
            if (s1.IsSupersetOf(s3))
            {
                Console.WriteLine("s1 is superset of s3");
            }
            else
            {
                Console.WriteLine("s1 is not superset of s3");
            }
    
            //////////////////////////////
            //
            if (s3.IsSupersetOf(s1))
            {
                Console.WriteLine("s3 is superset of s1");
            }
            else
            {
                Console.WriteLine("s3 is not superset of s1");
            }


  • Remove
  • Set<Int32> s = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s.Add(i);
            }
    
            Console.WriteLine("Before remove");
            s.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
            Console.WriteLine(Environment.NewLine);
    
            s.Remove(0);
            s.Remove(1);
            s.Remove(2);
    
            Console.WriteLine("After remove");
            s.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
            Console.WriteLine(Environment.NewLine);

  • RemoveAll
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s.Add(i);
            }
    
            Console.WriteLine("Count before remove");
            s.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
    
            //Remove even number
            s.RemoveAll(delegate(Int32 n) { return n % 2 == 0; });
    
            Console.WriteLine("Count after remove even number");
            s.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
        }
    }

  • RemoveMany
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s.Add(i);
            }
    
            Int32[] arr = new Int32[5];
            for (Int32 i = 0; i < arr.Length; i++)
            {
                arr[i] = i;
            }
    
            Int32 removedCount = s.RemoveMany(arr);
            Console.WriteLine("Removed count from set:{0}", removedCount);
            s.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
        }
    }

  • SymmetricDifference
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s1 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s1.Add(i);
            }
    
            Set<Int32> s2 = new Set<Int32>();
            for (Int32 i = 0; i < 20; i++)
            {
                s2.Add(i);
            }
    
            Set<Int32> s3 = s1.SymmetricDifference(s2);
            s3.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
        }
    }

  • SymmetricDifference
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s1 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s1.Add(i);
            }
    
            Set<Int32> s2 = new Set<Int32>();
            for (Int32 i = 0; i < 20; i++)
            {
                s2.Add(i);
            }
    
            Set<Int32> s3 = s1.SymmetricDifference(s2);
            s3.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
        }
    }

  • SymmetricDifferenceWith
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s1 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s1.Add(i);
            }
    
            Set<Int32> s2 = new Set<Int32>();
            for (Int32 i = 0; i < 20; i++)
            {
                s2.Add(i);
            }
    
            s1.SymmetricDifferenceWith(s2);
            s1.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
        }
    }

  • ToArray
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s.Add(i);
            }
    
            Int32[] arr = s.ToArray();
    
            Console.WriteLine("Before sort array");
            Array.ForEach(arr, delegate(Int32 n) { Console.WriteLine(n); });
    
            Array.Sort(arr);
    
            Console.WriteLine("After sort array");
            Array.ForEach(arr, delegate(Int32 n) { Console.WriteLine(n); });
        }
    }

  • TryGetItem
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s.Add(i);
            }
    
            Int32 foundItem;
            if (s.TryGetItem(0, out foundItem))
            {
                Console.WriteLine("Item 0 found");
            }
            else
            {
                Console.WriteLine("Item 0 not found");
            }
    
            if (s.TryGetItem(10, out foundItem))
            {
                Console.WriteLine("Item 10 found");
            }
            else
            {
                Console.WriteLine("Item 10 not found");
            }
        }
    }

  • Union
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Set<Int32> s1 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s1.Add(i);
            }
    
            Set<Int32> s2 = new Set<Int32>();
            for (Int32 i = 5; i < 15; i++)
            {
                s2.Add(i);
            }
    
            Set<Int32> union = s1.Union(s2);
            union.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
        }
    }



  • UnionWith
  • Set<Int32> s1 = new Set<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                s1.Add(i);
            }
    
            Set<Int32> s2 = new Set<Int32>();
            for (Int32 i = 5; i < 15; i++)
            {
                s2.Add(i);
            }
    
            s1.UnionWith(s2);
            s1.ForEach(delegate(Int32 n) { Console.WriteLine(n); });