Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string randomWords;
- randomWords = "apple banana apple orange pineapple blueberry raspberry lemon watermelon banana pineapple " +
- "strawberry blueberry orange mango kiwi melon raspberry apple orange";
- Dictionary<string, int> wordsCount = new Dictionary<string, int>();
- string[] words = randomWords.Split(' ');
- foreach(string word in words)
- {
- int count = 1;
- if (wordsCount.ContainsKey(word))
- {
- count = wordsCount[word] + 1;
- wordsCount[word] = count;
- }
- }
- foreach(var pair in wordsCount)
- {
- Console.WriteLine($"{pair.Key} - > {pair.Value}");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement