Пример #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!");

            }
        }
 static void Main()
 {
     Dictionary<string, string> dict = new Dictionary<string, string>();
     dict.Add(".NET", "platform for applications from Microsoft");
     dict.Add("CLR", "managed execution environment for .NET");
     dict.Add("namespace", "hierarchical organization of classes");
     Console.Write("Enter key: ");
     string key = Console.ReadLine();
     Console.WriteLine(dict[key]);
 }
Пример #3
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]);
     }
 }
Пример #4
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));
        }
Пример #5
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();
 }
Пример #6
0
 static void Main(string[] args)
 {
     Console.WriteLine("Please enter how many words:");
     IDictionary<string, string> dic = new Dictionary<string, string>();
     int wordsCount = int.Parse(Console.ReadLine());
     for (int i = 0; i < wordsCount; i++)
     {
         Console.WriteLine("Enter a word hit Enter and then the definition of that word: ");
         string word = Console.ReadLine();
         string definition = Console.ReadLine();
         dic.Add(word, definition);
     }
     Console.WriteLine("Now enter a word to search in the dictonary:");
     string word1 = Console.ReadLine();
     string result = string.Empty;
     dic.TryGetValue(word1, out  result);
     Console.WriteLine("-" + result);
 }
Пример #7
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]);
            }
        }