window.ENTITIES={'/api/snippets/cs/c%23%20count%20number%20of%20element%20occurrences%20in%20list':[{"result":true,"message":null,"batch":{"type":"cs","name":"c# count number of element occurrences in list","items":[{"id":"DN32Qp","type":"cs","name":"c# count number of element occurrences in List","content":"List myList = new List { \"A\", \"B\", \"B\", \"C\", \"C\", \"C\" };\n\nvar occurrences = myList.GroupBy(x => x).ToDictionary(y => y.Key, z => z.Count());\n\n// Output:\n// [A, 1]\n// [B, 2]\n// [C, 3]","source":"https://dirask.com/posts/C-NET-count-number-of-element-occurrences-in-List-DgWEQD","author":{"id":"507qGa","name":"Savannah","avatar":"1629142045068__507qGa__w40px_h40px.jpg","points":559,"role":"BASIC"},"creationTime":1645815735000,"updateTime":null,"removalTime":null},{"id":"pB69Mp","type":"cs","name":"c# count number of element occurrences in List","content":"using System;\nusing System.Linq;\nusing System.Collections.Generic;\n\npublic class Program\n{\n public static void Main()\n {\n List myList = new List { \"A\", \"B\", \"B\", \"C\", \"C\", \"C\" };\n\n var occurrences = myList.GroupBy(x => x).ToDictionary(y => y.Key, z => z.Count());\n\n foreach (var item in occurrences)\n Console.WriteLine(item);\n }\n}\n\n// Output:\n// Output:\n// [A, 1]\n// [B, 2]\n// [C, 3]","source":"https://dirask.com/posts/C-NET-count-number-of-element-occurrences-in-List-DgWEQD","author":{"id":"505ZRD","name":"kris_coder","avatar":"1586378805691__505ZRD__w40px_h40px.jpg","points":21050,"role":"BASIC"},"creationTime":1645815737000,"updateTime":null,"removalTime":null}]}}]};