Answer the question
In order to leave comments, you need to log in
How to extract only repeating N times elements of an array in C#?
Good afternoon, the task is such. There is an array of 1.5 million elements, each element contains a string.
These lines are repeated, and I need to extract from this array only those values that occur at least N times in the array.
For example, the strings "foo", "bar", and "new" occur, say, 3 times in the array (each), you need to transfer them to a new array, but not all occurrences, but only one that will say (yeah, dudes , in that array there are N more people like me, but here I am alone).
Thank you.
Answer the question
In order to leave comments, you need to log in
Alternatively, through a dictionary
Initializing the dictionary itself
Enumeration of the original array of strings with an entry in the dictionary of the string and the number of its repetitions
foreach (var item in StrArr)
{
if (!StringCount.ContainsKey(item))
StringCount.Add(item, 1);
else StringCount[item] += 1;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question