Copy codeThe Code is as follows: class Dirctonary
{
Public void DictionaryGet ()
{
Dictionary <int, string> productList = new System. Collections. Generic. Dictionary <int, string> ();
ProductList. Add (1, "ProductionOne ");
ProductList. Add (2, "ProductionTwo ");
Foreach (KeyValuePair <int, string> production in productList)
{
MessageBox. Show (string. Format ("{0}, {1}", production. Key, production. Value ));
}
// MessageBox. Show (productList. Count. ToString ());
// MessageBox. Show (productList [1]. ToString ());
Dictionary <int, string>. KeyCollection keys = productList. Keys;
Foreach (var item in keys)
{
MessageBox. Show (item. ToString ());
}
Dictionary <int, string>. ValueCollection collection = productList. Values;
Foreach (var item in collection)
{
MessageBox. Show (string. Format ("{0}", item ));
}
// ProductList. Remove (1 );
// ProductList. Clear ();
MessageBox. Show ("determines whether the key in the key-value pair is a" 1 "value ");
If (productList. ContainsKey (1 ))
{
MessageBox. Show (productList [1]);
}
MessageBox. Show ("determining whether a key-Value Pair contains a value of" ProductionTwo ");
If (productList. ContainsValue ("ProductionTwo "))
{
MessageBox. Show (string. Format ("{0}", "this really exists "));
}
}