Skip to Main Content
C# Cookbook, 2nd Edition
book

C# Cookbook, 2nd Edition

by Jay Hilyard, Stephen Teilhet
January 2006
Intermediate to advanced content levelIntermediate to advanced
1184 pages
43h 23m
English
O'Reilly Media, Inc.
Content preview from C# Cookbook, 2nd Edition
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Creating a Set Object
|
659
// Remove all nodes below node 'Two'.
// Nodes 'Five' and 'Six' are removed.
topLevel.GetRoot( ).BreadthFirstSearch("Two").RemoveNode(0);
// Remove node 'Three' from the root node.
topLevel.GetRoot( ).RemoveNode(1);
See Also
See the “Queue<T> Class” and “IComparable Interface” topics in the MSDN
documentation.
11.8 Creating a Set Object
Problem
You need an object that contains a group of unordered objects. This object must be
able to be compared to other objects containing sets of data. In addition, the two
must be able to have the following actions performed on them:
Union of the items contained by the two objects containing sets of data
Intersection of the items contained by the two objects containing sets of data
Difference of the items contained by the two objects containing sets of data
Solution
Create a Set<T> object, the code for which is shown in Example 11-17.
Example 11-17. Set class
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
public class Set<T> : IEnumerable<T>
{
private List<T> internalSet = new List<T>( );
public int Count
{
get {return (internalSet.Count);}
}
public T this[int index]
{
get
{
return (internalSet[index]);
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard
C# Cookbook

C# Cookbook

Joe Mayo
Head First C#, 4th Edition

Head First C#, 4th Edition

Andrew Stellman, Jennifer Greene

Publisher Resources

ISBN: 0596100639Supplemental ContentCatalog PageErrata