Пример #1
0
        /* A dictionary is stored as a sequence of text lines containing words and their explanations.
           Write a program that enters a word and translates it by using the dictionary.
          Sample dictionary:
            input 	        output
            .NET 	        platform for applications from Microsoft
             CLR 	        managed execution environment for .NET
             namespace   	hierarchical organization of classes
         */
        static void Main()
        {
            string text = @".NET-platform for applications from Microsoft
                             CLR-managed execution environment for .NET
                             namespace-hierarchical organization of classes";
            //Console.WriteLine(dictionary);
            char[] separators = { '\n', '-' };
            string[] arrDictionary = text.Split(separators, StringSplitOptions.RemoveEmptyEntries);
            var dictionaryMap = new Dictionary<string, string>();
            for (int i = 0; i < arrDictionary.Length; i += 2)
            {
                dictionaryMap.Add(arrDictionary[i], arrDictionary[i + 1]);
            }
            Console.WriteLine("Enter word:");
            string word = Console.ReadLine();
            if (dictionaryMap.ContainsKey(word))
            {
                Console.WriteLine(dictionaryMap[word]);
            }
            else
            {
                Console.WriteLine("there is no such word!");

            }
        }
Пример #2
0
 static void Main(string[] args)
 {
     Dictionary<string, string> dictionary = new Dictionary<string, string>();
     dictionary.Add(".NET", "Platform for applications from Microsoft");
     dictionary.Add("CLR", "	Managed execution environment for .NET");
     dictionary.Add("namespace", "Hierarchical organization of classes");
     Console.Write("Enter a word! ");
     string word = Console.ReadLine();
     if (dictionary.ContainsKey(word))
     {
         Console.WriteLine(dictionary[word]);
     }
 }
Пример #3
0
        static void Main(string[] args)
        {
            Dictionary<string, string> dict = new Dictionary<string, string>
            {
            {".NET", "platform for applications from Microsoft"},
            {"CLR", "managed execution environment for .NET"},
            {"NAMESPACE", "hierarchical organization of classes"}
            };

            Console.WriteLine("Dictionary words: {0}\n", string.Join(", ", dict.Keys));

            Console.Write("Enter a word to see its explanation: ");
            string word = Console.ReadLine().ToUpper();

            Console.WriteLine(dict.ContainsKey(word) ? string.Format("\n{0} -> {1}\n", word, dict[word])
                              : string.Format("\nDictionary does not contain word \"{0}\".\n", word));
        }
Пример #4
0
 static void Main()
 {
     Dictionary<string, string> wordDictionary = new Dictionary<string, string>();
     wordDictionary.Add(".NET", "platform for applications from Microsoft");
     wordDictionary.Add("CLR", "managed execution environment for .NET");
     wordDictionary.Add("namespace", "hierarchical organization of classes");
     Console.WriteLine("Please enter a word to secrh our dictionary:");
     string input = Console.ReadLine();
     if (wordDictionary.ContainsKey(input))
     {
         Console.WriteLine(wordDictionary[input]);
     }
     else
     {
         Console.WriteLine("No such word in the dictionary.");
     }
     Console.WriteLine();
 }
Пример #5
0
        static void Main(string[] args)
        {
            //A dictionary is stored as a sequence of text lines containing words and their explanations.
            //Write a program that enters a word and translates it by using the dictionary.

            Dictionary<string, string> dictionary =
                new Dictionary<string, string>();

            dictionary.Add(".NET", "platform for applications from Microsoft");
            dictionary.Add("CLR", "managed execution environment for .NET");
            dictionary.Add("namespace", "hierarchical organization of classes");
            Console.WriteLine("Please enter a word");
            string word = Console.ReadLine();
            // See whether Dictionary contains this string.
            if (dictionary.ContainsKey(word))
            {
                Console.WriteLine(dictionary[word]);
            }
        }