Exemplo n.º 1
0
    static void Main()
    {
        Console.WriteLine("Enter name and phone separated by dash or 'search' command:");
        string input = Console.ReadLine();
        var phonebook = new MyDictonary<string, string>();
        while (input != SearchCommand)
        {
            var elements = input.Split('-');
            try
            {
                phonebook.Add(elements[0], elements[1]);
            }
            catch (IndexOutOfRangeException)
            {
                Console.WriteLine("Invalid input: " + input);
            }
            catch (ArgumentException ae)
            {
                Console.WriteLine(ae.Message);
            }

            input = Console.ReadLine();
        }

        input = Console.ReadLine();
        while(input != string.Empty)
        {
            string number = null;
            try
            {
                number = phonebook.Get(input);
            }
            catch (KeyNotFoundException)
            {
                Console.WriteLine("Contact {0} does not exist.", input);
            }

            if (number != null)
            {
                Console.WriteLine("{0} -> {1}", input, number);
            }

            input = Console.ReadLine();
        }
    }
Exemplo n.º 2
0
    static void Main()
    {
        Console.WriteLine("Enter symbols:");
        string line = Console.ReadLine();
        var symbolsCount = new MyDictonary<char, int>();
        foreach (char ch in line)
        {
            if (!symbolsCount.ContainsKey(ch))
            {
                symbolsCount.Add(ch, 0);
            }

            symbolsCount[ch]++;
        }

        symbolsCount.OrderBy(item => item.Key);

        var keys = symbolsCount.Keys.OrderBy(value => value);
        foreach (var key in keys)
        {
            Console.WriteLine("{0}: {1} time/s", key, symbolsCount[key]);
        }
    }