Wintellect Power Collections Libraryを使う Bag編

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

Add
AddMany
AddRepresentative
AsReadOnly
ChangeNumberOfCopies
Clear
Clone
CloneContents
Contains
ConvertAll<(Of )>
CopyTo
CountWhere
Difference
DifferenceWith
DistinctItems
Equals
Exists
FindAll
ForEach
GetEnumerator
GetHashCode
GetRepresentativeItem
GetType
Intersection
IntersectionWith
IsDisjointFrom
IsEqualTo
IsProperSubsetOf
IsProperSupersetOf
IsSubsetOf
IsSupersetOf
NumberOfCopies
Remove
RemoveAll
RemoveAllCopies
RemoveMany
Sum
SumWith
SymmetricDifference
SymmetricDifferenceWith
ToArray
ToString
TrueForAll
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()
        {
            Bag<Int32> bag = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag.Add(i);
                bag.Add(i);
            }
            bag.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
        }
    }

  • 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);
            }
    
            Bag<Int32> bag = new Bag<Int32>();
            bag.AddMany(l);
            bag.AddMany(arr);
            bag.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
        }
    }


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


  • ChangeNumberOfCopies
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Bag<Int32> bag = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag.Add(i);
                bag.Add(i);
            }
    
            bag.ChangeNumberOfCopies(999, 100);
            bag.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
        }
    }


  • Clear
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Bag<Int32> bag = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag.Add(i);
                bag.Add(i);
            }
    
    
            bag.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
    
            bag.Clear();
    
            Console.WriteLine("Count after clear:{0}", bag.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()
        {
            Bag<Int32> bag = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag.Add(i);
                bag.Add(i);
            }
    
            Bag<Int32> cloneBag = bag.Clone();
            cloneBag.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
        }
    }


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


  • Contains
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Bag<Int32> bag = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag.Add(i);
                bag.Add(i);
            }
    
            if (bag.Contains(0))
            {
                Console.WriteLine("Contains 0");
            }
    
            if (!bag.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()
        {
            Bag<Int32> bag = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag.Add(i);
                bag.Add(i);
            }
    
    
            IEnumerable squares =
                bag.ConvertAll<Int32>(delegate(Int32 n)
                {
                    return n * n;
                });
            foreach (Int32 i in squares)
            {
                Console.WriteLine(i);
            }
    
    
            IEnumerable<String> details =
                bag.ConvertAll<String>(delegate(Int32 n)
                {
                    return String.Format("Bag 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()
        {
            Bag<Int32> bag = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag.Add(i);
                bag.Add(i);
            }
    
            Int32[] arr = new Int32[bag.Count];
            bag.CopyTo(arr, 0);
            bag.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
        }
    }


  • CountWhere
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Bag<Int32> bag = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag.Add(i);
                bag.Add(i);
            }
    
            Int32 evens =
                bag.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()
        {
            Bag<Int32> bag1 = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag1.Add(i);
                bag1.Add(i);
            }
    
            Bag<Int32> bag2 = new Bag<Int32>();
            for (Int32 i = 0; i < 5; i++)
            {
                bag2.Add(i);
                bag2.Add(i);
            }
    
            Bag<Int32> diff = bag1.Difference(bag2);
            diff.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
        }
    }


  • DifferenceWith
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Bag<Int32> bag1 = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag1.Add(i);
                bag1.Add(i);
            }
    
            Bag<Int32> bag2 = new Bag<Int32>();
            for (Int32 i = 0; i < 5; i++)
            {
                bag2.Add(i);
                bag2.Add(i);
            }
    
            bag1.DifferenceWith(bag2);
            bag1.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
        }
    }


  • Exists
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Bag<Int32> bag = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag.Add(i);
                bag.Add(i);
            }
    
            Boolean ret =
                bag.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()
        {
            Bag<Int32> bag = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag.Add(i);
                bag.Add(i);
            }
    
            IEnumerable<Int32> evens =
                bag.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()
        {
            Bag<Int32> bag = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag.Add(i);
                bag.Add(i);
            }
    
            bag.ForEach(delegate(Int32 n)
            {
                Console.WriteLine("Bag Element:{0}", n);
            });
        }
    }


  • GetRepresentativeItem
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Bag<Int32> bag = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag.Add(i);
                bag.Add(i);
            }
    
            Int32 representative;
            Int32 count = bag.GetRepresentativeItem(0, out representative);
            Console.WriteLine("Number of item 0 stored in the bag:{0}", count);
        }
    }


  • Intersection
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Bag<Int32> bag1 = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag1.Add(i);
                bag1.Add(i);
            }
    
            Bag<Int32> bag2 = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag2.Add(i * 2);
                bag2.Add(i * 2);
            }
    
            Bag<Int32> intersection = bag1.Intersection(bag2);
            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()
        {
            Bag<Int32> bag1 = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag1.Add(i);
                bag1.Add(i);
            }
    
            Bag<Int32> bag2 = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag2.Add(i * 2);
                bag2.Add(i * 2);
            }
    
            bag1.IntersectionWith(bag2);
            bag1.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()
        {
            Bag<Int32> bag1 = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag1.Add(i);
            }
    
            Bag<Int32> bag2 = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag2.Add(i * 2);
                bag2.Add(i * 2);
            }
    
            Bag<Int32> bag3 = new Bag<Int32>();
            for (Int32 i = 100; i < 110; i++)
            {
                bag3.Add(i);
            }
    
            Console.WriteLine(bag1.IsDisjointFrom(bag2));
            Console.WriteLine(bag1.IsDisjointFrom(bag3));
        }
    }


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


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


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


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


  • IsSupersetOf
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Bag<Int32> bag1 = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag1.Add(i);
                bag1.Add(i);
            }
    
            Bag<Int32> bag2 = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag2.Add(i);
                bag2.Add(i);
            }
    
            Bag<Int32> bag3 = new Bag<Int32>();
            for (Int32 i = 0; i < 9; i++)
            {
                bag3.Add(i);
                bag3.Add(i);
            }
    
            //////////////////////////////
            //
            if (bag1.IsSupersetOf(bag2))
            {
                Console.WriteLine("bag1 is superset of bag2");
            }
            else
            {
                Console.WriteLine("bag1 is not superset of bag2");
            }
    
            //////////////////////////////
            //
            if (bag2.IsSupersetOf(bag1))
            {
                Console.WriteLine("bag2 is superset of bag1");
            }
            else
            {
                Console.WriteLine("bag2 is not superset of bag1");
            }
    
            //////////////////////////////
            //
            if (bag1.IsSupersetOf(bag3))
            {
                Console.WriteLine("bag1 is superset of bag3");
            }
            else
            {
                Console.WriteLine("bag1 is not superset of bag3");
            }
    
            //////////////////////////////
            //
            if (bag3.IsSupersetOf(bag1))
            {
                Console.WriteLine("bag3 is superset of bag1");
            }
            else
            {
                Console.WriteLine("bag3 is not superset of bag1");
            }
        }
    }


  • NumberOfCopies
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Bag<Int32> bag = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag.Add(i);
                bag.Add(i);
            }
    
            Int32 numberOfItems = bag.NumberOfCopies(0);
            Console.WriteLine("Number of items '0':{0}", numberOfItems);
        }
    }


  • Remove
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Bag<Int32> bag = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag.Add(i);
                bag.Add(i);
            }
    
            Console.WriteLine("Before remove");
            bag.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
            Console.WriteLine(Environment.NewLine);
    
            bag.Remove(0);
            bag.Remove(1);
            bag.Remove(2);
    
            Console.WriteLine("After remove");
            bag.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()
        {
            Bag<Int32> bag = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag.Add(i);
                bag.Add(i);
            }
    
            Console.WriteLine("Count before remove");
            bag.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
    
            //Remove even number
            bag.RemoveAll(delegate(Int32 n) { return n % 2 == 0; });
    
            Console.WriteLine("Count after remove even number");
            bag.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
        }
    }


  • RemoveAllCopies
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Bag<Int32> bag = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag.Add(i);
                bag.Add(i);
            }
    
            bag.RemoveAllCopies(0);
            bag.RemoveAllCopies(1);
            bag.RemoveAllCopies(2);
            bag.RemoveAllCopies(3);
            bag.RemoveAllCopies(4);
    
            bag.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()
        {
            Bag<Int32> bag = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag.Add(i);
                bag.Add(i);
            }
    
            Int32[] arr = new Int32[5];
            for (Int32 i = 0; i < arr.Length; i++)
            {
                arr[i] = i;
            }
    
            Int32 removedCount = bag.RemoveMany(arr);
            Console.WriteLine("Removed count from bag:{0}", removedCount);
            bag.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
    
            removedCount = bag.RemoveMany(arr);
            Console.WriteLine("Removed count from bag:{0}", removedCount);
            bag.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
        }
    }


  • Sum
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Bag<Int32> bag1 = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag1.Add(i);
                bag1.Add(i);
            }
    
            Bag<Int32> bag2 = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag2.Add(i + 10);
                bag2.Add(i + 10);
            }
    
            Bag<Int32> sum = bag1.Sum(bag2);
            sum.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
        }
    }


  • SumWith
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Bag<Int32> bag1 = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag1.Add(i);
                bag1.Add(i);
            }
    
            Bag<Int32> bag2 = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag2.Add(i + 10);
                bag2.Add(i + 10);
            }
    
            bag1.SumWith(bag2);
            bag1.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()
        {
            Bag<Int32> bag1 = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag1.Add(i);
                bag1.Add(i);
            }
    
            Bag<Int32> bag2 = new Bag<Int32>();
            for (Int32 i = 0; i < 20; i++)
            {
                bag2.Add(i);
                bag2.Add(i);
            }
    
            Bag<Int32> bag3 = bag1.SymmetricDifference(bag2);
            bag3.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()
        {
            Bag<Int32> bag1 = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag1.Add(i);
                bag1.Add(i);
            }
    
            Bag<Int32> bag2 = new Bag<Int32>();
            for (Int32 i = 0; i < 20; i++)
            {
                bag2.Add(i);
                bag2.Add(i);
            }
    
            bag1.SymmetricDifferenceWith(bag2);
            bag1.ForEach(delegate(Int32 n) { Console.WriteLine(n); });
        }
    }


  • Sort
  • using System;
    using System.Text;
    using System.Collections;
    using System.Collections.Generic;
    using Wintellect.PowerCollections;
    
    public static class WintellectPowerCollections
    {
        public static void Main()
        {
            Bag<Int32> bag = new Bag<Int32>();
            for (Int32 i = 0; i < 10; i++)
            {
                bag.Add(i);
                bag.Add(i);
            }
    
            Int32[] arr = bag.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); });
        }
    }


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

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