
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
672
|
Chapter 11: Data Structures and Algorithms
The subset operation is performed only through a single method called IsSubsetOf.
The superset operation is also performed using a single method called
IsSupersetOf.
The following code demonstrates these two operations:
bool isSubset = set1.IsSubsetOf(set2);
bool isSuperset = set1.IsSupersetOf(set2);
The equivalence operation is performed using either the overloaded == operator or
the
Equals method. Since the == operator was overloaded, the != operator must also
be overloaded. The
!= operator returns the inverse of the == operator or Equals
method. The following code demonstrates these three operations:
bool isEqual = set1.Equals(set2);
isEqual = set1 == set2;
bool isNotEqual = set1 != set2;
See Also
See the “List<T> Class,” “Overloadable Operators,” and “Operator Overloading
Tutorial” topics in the MSDN documentation.