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.
628
|
Chapter 11: Data Structures and Algorithms
Items may be added to a MultiMap<T,U> object by running the code shown in
Example 11-9.
ContainsValue method Returns a bool indicating whether the MultiMap<T,U> contains a particular value. Its
syntax is:
ContainsValue(T value)
where value is the object to be found in the MultiMap<T,U>.
Remove method Removes a key from the MultiMap<T,U> and all its referent values in the internal map
Dictionary<T, List<U>>
. Its syntax is:
Remove(T key)
where key is the key to be removed.
Example 11-9. Testing the MultiMap class
public static void TestMultiMap( )
{
string s = "foo";
// Create and populate a MultiMap object.
MultiMap<int, string> myMap = new MultiMap<int, string>( );
myMap.Add(0, "zero");
myMap.Add(1, "one");
myMap.Add(2, "two");
myMap.Add(3, "three");
myMap.Add(3, "duplicate three");
myMap.Add(3, "duplicate three");
myMap.Add(4, "null");
myMap.Add(5, s);
myMap.Add(6, s);
// Display contents.
foreach (KeyValuePair<int, List<string>> entry in myMap)
{
Console.Write("Key: " + entry.Key.ToString( ) + "\tValue: ");
foreach (string str in myMap[entry.Key])
{
Console.Write(str + " : ");
}
Console.WriteLine( );
}
// Obtain values through the indexer.
Console.WriteLine( );
Console.WriteLine("((ArrayList) myMap[3])[0]: " + myMap[3][0]);
Console.WriteLine("((ArrayList) ...
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