Пример #1
0
        private static void Main()
        {
            var multiDictionary = new MultiDictionary <int, string>
            {
                { 1, "one" },
                { 2, "two" },
                { 3, "three" },
                { 1, "ich" },
                { 2, "nee" },
                { 3, "sun" }
            };

            Display(multiDictionary);

            multiDictionary.Remove(1);
            Display(multiDictionary);

            multiDictionary.Remove(3, "three");
            Display(multiDictionary);

            multiDictionary.Remove(1, "one");
            Display(multiDictionary);

            multiDictionary.Add(1, "ich");
            Display(multiDictionary);

            multiDictionary.Clear();
            Display(multiDictionary);
        }
Пример #2
0
        static void Main(string[] args)
        {
            MultiDictionary <int, string> dictionary = new MultiDictionary <int, string>();

            dictionary.Add(1, "one");
            dictionary.Add(2, "two");
            dictionary.Add(3, "three");
            dictionary.Add(1, "ich");
            dictionary.Add(2, "nee");
            dictionary.Add(3, "sun");

            foreach (KeyValuePair <int, string> kvp in dictionary)
            {
                Console.WriteLine(kvp.Key + " " + kvp.Value);
            }

            Console.WriteLine("Count: " + dictionary.Count);
            dictionary.Remove(1, "one");
            dictionary.Remove(3);
            foreach (KeyValuePair <int, string> kvp in dictionary)
            {
                Console.WriteLine(kvp.Key + " " + kvp.Value);
            }

            Console.WriteLine("Count: " + dictionary.Count);
        }
        static void Main(string[] args)
        {
            IMultiDictionary <int, string> multiDictionary = new MultiDictionary <int, string>();

            multiDictionary.Add(1, "one");
            multiDictionary.Add(1, "ich");
            multiDictionary.Add(1, "odin");
            multiDictionary.Add(2, "two");
            multiDictionary.Add(2, "nee");
            multiDictionary.Add(2, "dva");
            multiDictionary.Add(3, "three");
            multiDictionary.Add(3, "sun");
            multiDictionary.Add(3, "tri");

            Console.WriteLine("Is contains key 1?");
            Console.WriteLine(multiDictionary.ContainsKey(1));

            Console.WriteLine("Is contains key 5?");
            Console.WriteLine(multiDictionary.ContainsKey(5));

            Console.WriteLine("Is contains pair [1, odin]?");
            Console.WriteLine(multiDictionary.Contains(1, "odin"));

            Console.WriteLine("Is contains pair [2, shtain]?");
            Console.WriteLine(multiDictionary.Contains(2, "shtain"));

            foreach (var pair in multiDictionary)
            {
                Console.WriteLine(pair);
            }

            Console.WriteLine("Count is: {0}", multiDictionary.Count);

            Console.WriteLine("Keys:");
            foreach (var key in multiDictionary.Keys)
            {
                Console.WriteLine(key);
            }

            Console.WriteLine("Values:");
            foreach (var key in multiDictionary.Values)
            {
                Console.WriteLine(key);
            }

            Console.WriteLine("Is remove key 6 successfull? {0}", multiDictionary.Remove(6));
            Console.WriteLine("Is remove pair [2, two] successfull? {0}", multiDictionary.Remove(2, "two"));

            foreach (var pair in multiDictionary)
            {
                Console.WriteLine(pair);
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            var englishJapaneseDictionary = new MultiDictionary <int, string> ();

            Console.WriteLine("Testing counter: MultiDictionary has {0} values.", englishJapaneseDictionary.Count);

            Console.WriteLine();
            Console.WriteLine("Initial values:");
            englishJapaneseDictionary.Add(1, "one");
            englishJapaneseDictionary.Add(2, "two");
            englishJapaneseDictionary.Add(3, "three");
            englishJapaneseDictionary.Add(1, "ice");
            englishJapaneseDictionary.Add(2, "nee");
            englishJapaneseDictionary.Add(3, "sun");
            englishJapaneseDictionary.PrintDictionary();

            Console.WriteLine();
            Console.WriteLine("Testing Add \"tres\" and \"trois\" to key number 3:");
            englishJapaneseDictionary.Add(3, "tres");
            englishJapaneseDictionary.Add(3, "trois");
            englishJapaneseDictionary.PrintDictionary();

            Console.WriteLine();
            Console.WriteLine("Testing Remove with 1 and 2 parameters, removing value \"three\" and all values at key number 2:");
            englishJapaneseDictionary.Remove(3, "three");
            englishJapaneseDictionary.Remove(2);
            englishJapaneseDictionary.PrintDictionary();
            Console.WriteLine("Testing Remove when there is nothing to remove- same parameters as before:");
            Console.WriteLine(englishJapaneseDictionary.Remove(3, "three"));
            Console.WriteLine(englishJapaneseDictionary.Remove(2));

            Console.WriteLine();
            Console.WriteLine("Testing counter: MultiDictionary has {0} values.", englishJapaneseDictionary.Count);

            Console.WriteLine();
            Console.WriteLine("Testing Contains \"ice\" at key number 1:");
            Console.WriteLine(englishJapaneseDictionary.Contains(1, "ice"));
            Console.WriteLine("Testing Contains \"ice\" at key number 3:");
            Console.WriteLine(englishJapaneseDictionary.Contains(3, "ice"));
            Console.WriteLine("Testing ContainsKey 3:");
            Console.WriteLine(englishJapaneseDictionary.ContainsKey(3));
            Console.WriteLine("Testing ContainsKey 2:");
            Console.WriteLine(englishJapaneseDictionary.ContainsKey(2));

            Console.WriteLine();
            Console.WriteLine("Testing Clear:");
            englishJapaneseDictionary.Clear();
            Console.WriteLine("Printing Table:");
            englishJapaneseDictionary.PrintDictionary();
            Console.WriteLine("Testing counter: MultiDictionary has {0} values.", englishJapaneseDictionary.Count);
        }
Пример #5
0
        public static void Main(string[] args)
        {
            var dictionary = new MultiDictionary <Keys, myString>
            {
                { 1, "one" },
                { 2, "two" },
                { 3, "three" },
                { 1, "ich" },
                { 2, "nee" },
                { 3, "sun" }
            };

            PrintDictionary(dictionary);

            Console.WriteLine($"Does the dictionary contain a key \"1\"? \n{dictionary.ContainsKey(1)} to that brother");
            Console.WriteLine($"Does the dictionary contain a key \"3\" and value \"sun\" ? \n{dictionary.Contains(3, "sun")} to that brother\n");
            Console.WriteLine("Removing all one's");
            try
            {
                dictionary.Remove(1);
            }
            catch (ArgumentOutOfRangeException e)
            {
                Console.WriteLine("there was no key called \"1\"");
            }

            PrintDictionary(dictionary);
            Console.WriteLine($"Now, does the dictionary contain a key \"1\"? \n{dictionary.ContainsKey(1)} to that brother\n");

            Console.WriteLine("Removing just \"nee\":");
            dictionary.Remove(2, "nee");
            PrintDictionary(dictionary);

            Console.WriteLine($"Now, does the dictionary contain a key \"2\" and value \"nee\"? \n{dictionary.Contains(2, "nee")} to that brother\n");

            Console.WriteLine("Clearing Dictionary");
            dictionary.Clear();
            PrintDictionary(dictionary);
        }
Пример #6
0
        private static void Main()
        {
            var multiDictionary = new MultiDictionary <numberWithAttribute, StringBuilder>();

            numberWithAttribute number;

            number.num = 1;


            multiDictionary.CreateNewValue(number);

            Display(multiDictionary);
            multiDictionary.Remove(number);
            Display(multiDictionary);
            Console.Read();
        }
        private static void Execute(string[] args)
        {
            var numbers = new MultiDictionary <int, string>
            {
                { 1, "one" },
                { 2, "two" },
                { 3, "three" },
                { 1, "ich" },
                { 2, "nee" },
                { 3, "sun" }
            };

            DisplayValues(numbers);
            DisplayKeyValues(numbers);

            numbers.Remove(1);

            DisplayValues(numbers);
        }
Пример #8
0
        public static void Main(string[] args)
        {
            var dictionary = new MultiDictionary <int, string>
            {
                { 1, "one" },
                { 2, "two" },
                { 3, "three" },
                { 1, "ich" },
                { 2, "nee" },
                { 3, "sun" }
            };

            Console.WriteLine("Initial state:");
            DisplayDictionary(dictionary);

            Console.WriteLine("After Removing key = 3, value = sun:");
            dictionary.Remove(3, "sun");
            DisplayDictionary(dictionary);

            Console.WriteLine("After Removing key = 3:");
            dictionary.Remove(3);
            DisplayDictionary(dictionary);

            Console.WriteLine("After Removing key = 1:");
            dictionary.Remove(1);
            DisplayDictionary(dictionary);

            Console.WriteLine("Returning to Initial state:");
            dictionary.Add(1, "one");
            dictionary.Add(1, "ich");
            dictionary.Add(3, "three");
            dictionary.Add(3, "sun");
            DisplayDictionary(dictionary);

            Console.WriteLine("After Clearing the dictionary:");
            dictionary.Clear();
            DisplayDictionary(dictionary);

            Console.WriteLine("Returning to Initial state:");
            dictionary.Add(1, "one");
            dictionary.Add(1, "ich");
            dictionary.Add(2, "two");
            dictionary.Add(2, "nee");
            dictionary.Add(3, "three");
            dictionary.Add(3, "sun");
            DisplayDictionary(dictionary);

            Console.WriteLine("The values are:");
            foreach (var value in dictionary.Values)
            {
                Console.WriteLine(value);
            }

            Console.WriteLine();
            Console.WriteLine("The Keys are:");
            foreach (var key in dictionary.Keys)
            {
                Console.WriteLine(key);
            }

            Console.WriteLine();
            Console.WriteLine(dictionary.Contains(1, "one")
                ? "The Multi Dictionary contains key = 1, value = one"
                : "The Multi Dictionary does not contain key = 1, value = one");

            Console.WriteLine(dictionary.ContainsKey(3)
                ? "The Multi Dictionary contains key = 3"
                : "The Multi Dictionary does not contain key = 3");
        }
Пример #9
0
        static void Main(string[] args)
        {
            MultiDictionary <int, string> multyDictionary = new MultiDictionary <int, string>();

            //add values
            multyDictionary.Add(1, "one");
            multyDictionary.Add(1, "ich");
            multyDictionary.Add(2, "two");
            multyDictionary.Add(2, "nee");
            multyDictionary.Add(3, "three");
            multyDictionary.Add(3, "sun");

            // ienumrable
            foreach (var item in multyDictionary)
            {
                Console.WriteLine(item.Value);
            }

            IEnumerable d = multyDictionary;

            foreach (var item in d)
            {
                Console.WriteLine(item.ToString());
            }

            // contains
            string ans;

            if (multyDictionary.ContainsKey(3))
            {
                ans = "contains 3";
            }
            else
            {
                ans = "not contains 3";
            }
            if (multyDictionary.ContainsKey(4))
            {
                ans += " and contains 4";
            }
            else
            {
                ans += " and not contains 4";
            }
            if (multyDictionary.Contains(3, "three"))
            {
                ans += " and contains 3,three";
            }
            else
            {
                ans += " and not contains 3,three";
            }
            if (multyDictionary.Contains(3, "aa"))
            {
                ans += " and contains 3,aa";
            }
            else
            {
                ans += " and not contains 3,aa";
            }

            Console.WriteLine(ans);

            // count and remove
            Console.WriteLine("there are " + multyDictionary.Count + " items in the collection");
            multyDictionary.Remove(1, "one");
            Console.WriteLine("there are " + multyDictionary.Count + " items in the collection");

            multyDictionary.Remove(2);
            Console.WriteLine("there are " + multyDictionary.Count + " items in the collection");

            //clear
            multyDictionary.Clear();
            Console.WriteLine("there are " + multyDictionary.Count + " items in the collection");
        }
        static void Main(string[] args)
        {
            MultiDictionary <int, string> md = new  MultiDictionary <int, string>();

            md.Add(1, "one");
            md.Add(2, "two");
            md.Add(3, "three");
            md.Add(1, "ich");
            md.Add(2, "nee");
            md.Add(3, "sun");
            Console.WriteLine("*******************************");
            Console.WriteLine("checking IEnumerable: ");
            foreach (var val in (IEnumerable)md)
            {
                Console.WriteLine(val);
            }
            Console.WriteLine("*******************************");
            Console.WriteLine("your multiDictionary size: " + md.Count);
            Console.WriteLine("*******************************");
            Console.WriteLine("remove key 1");
            md.Remove(1);
            Console.WriteLine("*******************************");

            Console.WriteLine("your multiDictionary size after: " + md.Count);
            Console.WriteLine("*******************************");
            Console.WriteLine("checking IEnumerable: ");
            foreach (var val in (IEnumerable)md)
            {
                Console.WriteLine(val);
            }
            Console.WriteLine("*******************************");
            Console.WriteLine("remove (2,two)");
            md.Remove(2, "two");
            Console.WriteLine("your multiDictionary size after: " + md.Count);
            Console.WriteLine("*******************************");
            Console.WriteLine("checking IEnumerable: ");
            foreach (var val in (IEnumerable)md)
            {
                Console.WriteLine(val);
            }
            Console.WriteLine("*******************************");

            Console.WriteLine("try to remove value that not exits return: " + md.Remove(3, "kkkk"));
            Console.WriteLine("*******************************");
            Console.WriteLine("checking contains (4,four) return " + md.Contains(4, "four"));
            Console.WriteLine("*******************************");
            Console.WriteLine("checking contains (3,three) return " + md.Contains(3, "three"));
            Console.WriteLine("*******************************");
            Console.WriteLine("checking contains (4) return " + md.ContainsKey(4));
            Console.WriteLine("*******************************");
            Console.WriteLine("checking contains (3) return " + md.ContainsKey(3));
            Console.WriteLine("*******************************");
            Console.WriteLine("your values: ");
            var values = md.Values;

            foreach (var val in (values))
            {
                Console.WriteLine(val);
            }
            Console.WriteLine("*******************************");
            Console.WriteLine("your keys: ");
            var keys = md.Keys;

            foreach (var key in keys)
            {
                Console.WriteLine(key);
            }
            Console.WriteLine("*******************************");
            Console.WriteLine("clear : ");
            md.Clear();
            Console.WriteLine("your multiDictionary size after: " + md.Count);
            Console.WriteLine("*******************************");
        }
Пример #11
0
        static void Main(string[] args)
        {
            MultiDictionary <int, string> dictionary = new MultiDictionary <int, string>();

            dictionary.Add(1, "one");
            dictionary.Add(2, "two");
            dictionary.Add(3, "three");
            dictionary.Add(1, "ich");
            dictionary.Add(2, "nee");
            dictionary.Add(3, "sun");

            ICollection <string> values1 = dictionary.Values;
            StringBuilder        sb      = new StringBuilder();

            if (dictionary.Count > 0)
            {
                Console.WriteLine("complete list:");
                Console.WriteLine();
                int i = 1;
                iter = dictionary.GetEnumerator();
                while (iter.MoveNext())
                {
                    sb.Append("Key: ");
                    sb.Append(iter.Current.Key.ToString());
                    sb.Append(" Value: ");
                    sb.Append(iter.Current.Value.ToString());
                    Console.WriteLine(sb.ToString());
                    i++;
                    sb.Clear();
                }
                Console.WriteLine();
            }


            System.Collections.Generic.ICollection <int> keys = dictionary.Keys;
            ICollection <string> values2 = dictionary.Values;
            bool test  = dictionary.Contains(3, "three");
            bool test2 = dictionary.Remove(3, "three");
            bool test3 = dictionary.Contains(3, "three");

            Console.WriteLine();

            Console.WriteLine("list after removing {3,three}");

            iter = dictionary.GetEnumerator();
            if (dictionary.Count > 0)
            {
                int i = 1;
                while (iter.MoveNext())
                {
                    sb.Append("Key: ");
                    sb.Append(iter.Current.Key.ToString());
                    sb.Append(" Value: ");
                    sb.Append(iter.Current.Value.ToString());
                    Console.WriteLine(sb.ToString());
                    i++;
                    sb.Clear();
                }
            }

            Console.WriteLine();
            bool test4 = dictionary.Remove(3);
            bool test5 = dictionary.Contains(3, "sun");

            Console.WriteLine("list after removing key number 3:");
            Console.WriteLine();
            iter = dictionary.GetEnumerator();
            if (dictionary.Count > 0)
            {
                int i = 1;
                while (iter.MoveNext())
                {
                    sb.Append("Key: ");
                    sb.Append(iter.Current.Key.ToString());
                    sb.Append(" Value: ");
                    sb.Append(iter.Current.Value.ToString());
                    Console.WriteLine(sb.ToString());
                    i++;
                    sb.Clear();
                }
            }
        }
Пример #12
0
        public static void Main()
        {
            MultiDictionary <int, string> multiDictionary = new MultiDictionary <int, string>();

            multiDictionary.Add(1, "one");
            multiDictionary.Add(2, "two");
            multiDictionary.Add(3, "three");
            multiDictionary.Add(1, "ich");
            multiDictionary.Add(2, "nee");
            multiDictionary.Add(3, "sun");

            foreach (KeyValuePair <int, string> item in multiDictionary)
            {
                Console.WriteLine("the key:{0}, the value: {1}", item.Key, item.Value);
            }

            Console.WriteLine("All the values in dictionary");
            foreach (string valueItem in multiDictionary.Values)
            {
                Console.WriteLine("{0},", valueItem);
            }
            Console.WriteLine("All the keys in the dictionary");

            foreach (int keyItem in multiDictionary.Keys)
            {
                Console.WriteLine("{0},", keyItem);
            }
            Console.WriteLine("the number of items in dictionary {0}", multiDictionary.Count);
            bool isRemoved = multiDictionary.Remove(1, "one");

            if (isRemoved)
            {
                Console.WriteLine("Dictionary after removal");
                foreach (KeyValuePair <int, string> item in multiDictionary)
                {
                    Console.WriteLine("the key:{0}, the value: {1}", item.Key, item.Value);
                }
            }
            else
            {
                Console.WriteLine("cant Remove this item");
            }

            bool isKeyRemoved = multiDictionary.Remove(1);

            if (isKeyRemoved)
            {
                Console.WriteLine("The dictionary after removal");
                foreach (KeyValuePair <int, string> item in multiDictionary)
                {
                    Console.WriteLine("the key:{0}, the value: {1}", item.Key, item.Value);
                }
            }
            else
            {
                Console.WriteLine("cant Remove this item ,its not exist");
            }

            bool isContainKey = multiDictionary.ContainKey(3);

            if (isContainKey)
            {
                Console.WriteLine("the dictionaty contains key");
            }
            else
            {
                Console.WriteLine("The key doesn't exist");
            }

            bool isContains = multiDictionary.Contains(3, null);

            if (isContains)
            {
                Console.WriteLine("The dictionary contains the value");
            }
            else
            {
                Console.WriteLine("No such value");
            }

            multiDictionary.Clear();
        }