Esempio n. 1
0
        static void Main(string[] args)
        {
            // Create a dictionary that contains no more than three entries.
            IDictionary d = new SimpleDictionary(3);

            // Add three people and their ages to the dictionary.
            d.Add("Jeff", 40);
            d.Add("Kristin", 34);
            d.Add("Aidan", 1);

            Console.WriteLine("Number of elements in dictionary = {0}", d.Count);

            Console.WriteLine("Does dictionary contain 'Jeff'? {0}", d.Contains("Jeff"));

            Console.WriteLine("Jeff's age is {0}", d["Jeff"]);

            // Display every entry's key and value.
            foreach (DictionaryEntry de in d)
            {
                Console.WriteLine("{0} is {1} years old.", de.Key, de.Value);
            }
            // Remove an entry that exists.
            d.Remove("Jeff");

            // Remove an entry that does not exist, but do not throw an exception.
            d.Remove("Max");

            // Show the names (keys) of the people in the dictionary.
            foreach (string s in d.Keys)
                Console.WriteLine(s);

            // Show the ages (values) of the people in the dictionary.
            foreach (int age in d.Values)
                Console.WriteLine(age);

        }
Esempio n. 2
0
 public SimpleDictionaryEnumerator(SimpleDictionary sd)
 {
     _items = new DictionaryEntry[sd.Count];
     Array.Copy(sd._items, 0, _items, 0, sd.Count);
 }