trying to get a count of each item in the array, however its adding a total number.
Dictionary<string, int> counts = new Dictionary<string, int>() {
{ "HelloWorld", 0},
{ "Hello", 0},
{ "World", 0},
{ "integer", 0},
};
foreach (var item in arraylist)
{
counts["HelloWorld"] += 1;
counts["Hello"] += 1;
counts["World"] += 1;
counts["integer"] += 1;
}
Console.WriteLine("");
foreach (KeyValuePair<string, int> item in counts)
{
Console.WriteLine(item.Key.ToString() + ":" + item.Value.ToString());
}
Console.ReadLine();
}
E.g. Input: 1,10
Expected output:
hello: 3
world: 5
helloworld: 1
integer: 11
Run below dotnet fiddle to find issue: