I have a list of lines where each element is free text describing the skill, so it looks like this:
List<string> list = new List<string> {"very good right now", "pretty good", "convinced me that is good", "pretty medium", "just medium" .....}
And I want to save a user account for these free texts. Therefore, at the moment I am using the conditions:
foreach (var item in list) { if (item.Contains("good")) { score += 2.5; Console.WriteLine("good skill, score+= 2.5, is now {0}", score); } else if (item.Contains(low")) { score += 1.0; Console.WriteLine("low skill, score+= 1.0, is now {0}", score); } }
Suppose that in my work I want to use a dictionary to compare points, for example:
Dictionary<string, double> dic = new Dictionary<string, double> { { "good", 2.5 }, { "low", 1.0 }};
What would be a good way to cross between dictionary values โโand a string list? Now I see it as a nested loop:
foreach (var item in list) { foreach (var key in dic.Keys) if (item.Contains(key)) score += dic[key]; }
But I'm sure there are better ways. Better to be faster or more pleasing to the eye (LINQ), at least.
Thanks.