Determines whether the ListDictionary contains a specific key.
using System;
using System.Collections;
using System.Collections.Specialized;
public class SamplesListDictionary {
public static void Main() {
ListDictionary myCol = new ListDictionary();
myCol.Add( "A", "1.49" );
myCol.Add( "B", "0.99" );
PrintKeysAndValues( myCol );
if ( myCol.Contains( "A" ) )
Console.WriteLine( "The collection contains the key \"A\"." );
else
Console.WriteLine( "The collection does not contain the key \"A\"." );
Console.WriteLine();
}
public static void PrintKeysAndValues( IDictionary myCol ) {
Console.WriteLine( " KEY VALUE" );
foreach ( DictionaryEntry de in myCol )
Console.WriteLine( " {0,-25} {1}", de.Key, de.Value );
Console.WriteLine();
}
}
Related examples in the same category