SHARE
TWEET

Untitled

a guest Dec 3rd, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  string randomWords;
  2.             randomWords = "apple banana apple orange pineapple blueberry raspberry lemon watermelon banana pineapple " +
  3.                 "strawberry blueberry orange mango kiwi melon raspberry apple orange";
  4.  
  5.             Dictionary<string, int> wordsCount = new Dictionary<string, int>();
  6.  
  7.             string[] words = randomWords.Split(' ');
  8.  
  9.             foreach(string word in words)
  10.             {
  11.                 int count = 1;
  12.                 if (wordsCount.ContainsKey(word))
  13.                 {
  14.                     count = wordsCount[word] + 1;
  15.                     wordsCount[word] = count;
  16.                 }
  17.                
  18.             }
  19.             foreach(var pair in wordsCount)
  20.             {
  21.                 Console.WriteLine($"{pair.Key} - > {pair.Value}");
  22.             }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top