You can use any object that implements the
To make a
It is also standard practice that at least one of your constructors takes an
A collection that contains no duplicate elements. This interface models the mathematical
- ///
None of the
The following table summarizes the binary operators that are supported by the
Implements an immutable (read-only)
Although this is advertised as immutable, it really isn't. Anyone with access to the
- ///
- /// The System.Collections namespace in the .NET Framework provides a number of collection
- /// types that are extremely useful for manipulating data in memory. However, there is one
- /// type of collection that is conspicuously missing from
- /// A
- ///
- /// With sets, adding elements, removing elements, and checking for the existence - /// of an element is fast and simple. You can mix and match the elements in different - /// sets using the supported mathematical set operators: union, intersection, - /// exclusive-or, and minus. - ///
- ///
- /// You will see some interesting side effects with different
- /// The following sample program demonstrates some of the features of sets:
- ///
- ///using System;
- ///using Iesi.Collections;
- ///namespace RiverDemo
- ///{
- /// class Rivers
- /// {
- /// [STAThread]
- /// static void Main(string[] args)
- /// {
- /// //Use Arrays (which are ICollection objects) to quickly initialize.
- /// Set arizona
- /// = new SortedSet(new string[] {"Colorado River"});
- /// Set california
- /// = new SortedSet(new string[] {"Colorado River", "Sacramento River"});
- /// Set colorado
- /// = new SortedSet(new string[] {"Arkansas River", "Colorado River", "Green River", "Rio Grande"});
- /// Set kansas
- /// = new SortedSet(new string[] {"Arkansas River", "Missouri River"});
- /// Set nevada
- /// = new SortedSet(new string[] {"Colorado River"});
- /// Set newMexico
- /// = new SortedSet(new string[] {"Rio Grande"});
- /// Set utah
- /// = new SortedSet(new string[] {"Colorado River", "Green River", "San Juan River"});
- /// //Rivers by region.
- /// Set southWest = colorado | newMexico | arizona | utah;
- /// Set midWest = kansas;
- /// Set west = california | nevada;
- /// //All rivers (at least for the demo).
- /// Set all = southWest | midWest | west;
- /// Print("All rivers:", all);
- /// Print("Rivers in the southwest:", southWest);
- /// Print("Rivers in the west:", west);
- /// Print("Rivers in the midwest:", midWest);
- /// Console.WriteLine();
- ///
- /// //Use the '-' operator to subtract the rivers in Colorado from
- /// //the set of all rivers.
- /// Print("Of all rivers, these don't pass through Colorado:", all - colorado);
- ///
- /// //Use the '&' operator to find rivers that are in Colorado AND in Utah.
- /// //A river must be present in both states, not just one.
- /// Print("Rivers common to both Colorado and Utah:", colorado & utah);
- ///
- /// //use the '^' operator to find rivers that are in Colorado OR Utah,
- /// //but not in both.
- /// Print("Rivers in Colorado and Utah that are not shared by both states:",
- /// colorado ^ utah);
- ///
- /// //Use the '&' operator to discover which rivers are present in Arizona,
- /// // California,Colorado, Nevada, and Utah. The river must be present in
- /// // all states to be counted.
- /// Print("Rivers common to Arizona, California, Colorado, Nevada, and Utah:",
- /// arizona & california & colorado & nevada & utah);
- /// //Just to prove to you that operators always return like types, let's do a
- /// //complex Set operation and look at the type of the result:
- /// Console.WriteLine("The type of this complex operation is: " +
- /// ((southWest ^ colorado & california) | kansas).GetType().FullName);
- /// }
- /// private static void Print(string title, Set elements)
- /// {
- /// Console.WriteLine(title);
- /// foreach(object o in elements)
- /// {
- /// Console.WriteLine("\t" + o);
- /// Console.WriteLine();
- /// }
- /// }
- /// }
- ///
- ///
- /// Although there are other kinds of sets available in the library, the example uses
- ///
- /// Here is the output from running the example:
- ///
- ///All rivers:
- ///Arkansas River
- ///Colorado River
- ///Green River
- ///Missouri River
- ///Rio Grande
- ///Sacramento River
- ///San Juan River
- ///
- ///Rivers in the southwest:
- ///Arkansas River
- ///Colorado River
- ///Green River
- ///Rio Grande
- ///San Juan River
- ///
- ///Rivers in the west:
- ///Colorado River
- ///Sacramento River
- ///
- ///Rivers in the midwest:
- ///Arkansas River
- ///Missouri River
- ///
- ///Of all rivers, these don't pass through Colorado:
- ///Missouri River
- ///Sacramento River
- ///San Juan River
- ///
- ///Rivers common to both Colorado and Utah:
- ///Colorado River
- ///Green River
- ///
- ///Rivers in Colorado and Utah that are not shared by both states:
- ///Arkansas River
- ///Rio Grande
- ///San Juan River
- ///
- ///Rivers common to Arizona, California, Colorado, Nevada, and Utah:
- ///Colorado River
- ///
- ///The type of this complex operation is:
- ///Iesi.Collections.SortedSet
- ///Press any key to continue
- ///
- ///
A collection that contains no duplicate elements. This class models the mathematical
- ///
None of the
The following table summarizes the binary operators that are supported by the
Implements a thread-safe