Click here to Skip to main content
15,886,069 members
Articles / Programming Languages / C#

Set Collections for C#

Rate me:
Please Sign up or sign in to vote.
4.85/5 (18 votes)
3 Feb 2008CPOL10 min read 115.1K   642   54  
Describes a library of set collections I have written
<html dir="LTR"><head><META http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"><title>Set Class</title><xml></xml><link rel="stylesheet" type="text/css" href="MSDN.css"></head><body id="bodyID" class="dtBODY"><div id="nsbanner"><div id="bannerrow1"><table class="bannerparthead" cellspacing="0"><tr id="hdr"><td class="runninghead">"Set" Collections Library for .NET</td><td class="product"></td></tr></table></div><div id="TitleRow"><h1 class="dtH1">Set Class</h1></div></div><div id="nstext"><p>A collection that contains no duplicate elements.  This class models the mathematical
            <code>Set</code> abstraction, and is the base class for all other <code>Set</code> implementations.  
            The order of elements in a set is dependant on (a)the data-structure implementation, and 
            (b)the implementation of the various <code>Set</code> methods, and thus is not guaranteed.</p><p><code>Set</code> overrides the <code>Equals()</code> method to test for "equivalency": whether the 
            two sets contain the same elements.  The "==" and "!=" operators are not overridden by 
            design, since it is often desirable to compare object references for equality.</p><p>Also, the <code>GetHashCode()</code> method is not implemented on any of the set implementations, since none
            of them are truely immutable.  This is by design, and it is the way almost all collections in 
            the .NET framework function.  So as a general rule, don't store collection objects inside <code>Set</code>
            instances.  You would typically want to use a keyed <code>IDictionary</code> instead.</p><p>None of the <code>Set</code> implementations in this library are guranteed to be thread-safe
            in any way unless wrapped in a <code>SynchronizedSet</code>.</p><p>The following table summarizes the binary operators that are supported by the <code>Set</code> class.</p><div class="tablediv"><table class="dtTABLE" cellspacing="0"><tr valign="top"><th width="50%">Operation</th><th width="50%">Description</th><th width="50%">Method</th><th width="50%">Operator</th></tr><tr valign="top"><td>Union (OR)</td><td>Element included in result if it exists in either <code>A</code> OR <code>B</code>.</td><td><code>Union()</code></td><td><code>|</code></td></tr><tr valign="top"><td>Intersection (AND)</td><td>Element included in result if it exists in both <code>A</code> AND <code>B</code>.</td><td><code>InterSect()</code></td><td><code>&amp;</code></td></tr><tr valign="top"><td>Exclusive Or (XOR)</td><td>Element included in result if it exists in one, but not both, of <code>A</code> and <code>B</code>.</td><td><code>ExclusiveOr()</code></td><td><code>^</code></td></tr><tr valign="top"><td>Minus (n/a)</td><td>Take all the elements in <code>A</code>.  Now, if any of them exist in <code>B</code>, remove
            		them.  Note that unlike the other operators, <code>A - B</code> is not the same as <code>B - A</code>.</td><td><code>Minus()</code></td><td><code>-</code></td></tr></table></div><p>For a list of all members of this type, see <a href="Iesi.Collections.SetMembers.html">Set Members</a>.</p><p><a href="ms-help://MS.NETFrameworkSDKv1.1/cpref/html/frlrfSystemObjectClassTopic.htm">System.Object</a><br>   <b>Set</b></p><div class="syntax"><span class="lang">[Visual Basic]</span><br>MustInherit Public Class Set<div>Implements ISet, ICollection, IEnumerable, ICloneable</div></div><div class="syntax"><span class="lang">[C#]</span><div>public abstract class Set : ISet, ICollection, IEnumerable, ICloneable</div></div><h4 class="dtH4">Requirements</h4><p><b>Namespace: </b><a href="Iesi.Collections.html">Iesi.Collections</a></p><p><b>Assembly: </b>Iesi.Collections (in Iesi.Collections.dll)
					</p><h4 class="dtH4">See Also</h4><p><a href="Iesi.Collections.SetMembers.html">Set Members</a> | <a href="Iesi.Collections.html">Iesi.Collections Namespace</a></p><object type="application/x-oleobject" classid="clsid:1e2a7bd0-dab9-11d0-b93a-00c04fc99f9e" viewastext="true" style="display: none;"><param name="Keyword" value="Set class, about Set class"></object><hr><div id="footer"><p></p><p>Generated from assembly Iesi.Collections [1.0.0.1]</p></div></div></body></html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Imagine Communications
United Kingdom United Kingdom
I have been working in IT since 1975, in various roles from junior programmer to system architect, and with many different languages and platforms. I have written shedloads of code.

I now live in Bedfordshire, England. As well as working full time I am the primary carer for my wife who has MS. I am learning to play the piano. I have three grown up children and a cat.

Comments and Discussions