Referring to this topic: Minimize LINQ string token counter
And using the following provided code:
string src = "for each character in the string, take the rest of the " +
"string starting from that character " +
"as a substring; count it if it starts with the target string";
var results = src.Split() // default split by whitespace
.GroupBy(str => str) // group words by the value
.Select(g => new
{
str = g.Key, // the value
count = g.Count() // the count of that value
});
I need to enumerate all values (keywords and number of occurrences) and load them into NameValueCollection. Due to my very limited Linq knowledge, can’t figure out how to make it. Please advise. Thanks.
I won’t guess why you want to put anything in a
NameValueCollection, but is there some reason whyis not sufficient?
(EDIT: Changed accessor to
Add, which may be better for your use case.)If the answer is “no, that works” you should probably stop and figure out what the hell the above code is doing before using it in your project.