コード例 #1
0
ファイル: Program.cs プロジェクト: idanmalka/CodeValue
        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);
        }
コード例 #2
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");
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: orele1995/SUBMISSIONS
        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");
        }
コード例 #4
0
        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("*******************************");
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: nellya27/labsOfCodeValue
        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();
        }