Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. List<string> words = new List<string>();
  2. cmd = new SqlCommand("Select tokens From tokens_all_comments", connection);
  3. connection.Open();
  4. dr = cmd.ExecuteReader();
  5. while (dr.Read())
  6. {
  7. words.Add(dr["tokens"].ToString());
  8. }
  9. dr.Close();
  10. connection.Close();
  11.  
  12. Dictionary<string, int> dictionary = new Dictionary<string, int>();
  13. foreach (string word in words)
  14. {
  15. if (word.Length != 0)
  16. {
  17. if ( dictionary.ContainsKey(word) )
  18. {
  19. dictionary[word]++;
  20. }
  21. else
  22. {
  23. dictionary[word] = 1;
  24. }
  25.  
  26. }
  27. }
  28. var sortedDict = (from entry in dictionary orderby entry.Value descending select entry).ToDictionary(pair => pair.Key, pair => pair.Value);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement