I'm trying to use a ConcurrentDictionary to help with a filtering task.
If a number appears in list, then I want to copy an entry from one dictionary to another.
But this part of the AddOrUpdate is not right - v.Add(number)
I get
"Cannot implicitly convert type 'void' to 'System.Collections.Generic.List'
And two more errors.
class Program
{
static void Main(string[] args)
{
Program p = new Program();
List<int> filter = new List<int> {1,2};
p.Filter(filter);
}
private void Filter(List<int> filter)
{
Dictionary<string, List<int>> unfilteredResults = new Dictionary<string, List<int>>();
unfilteredResults.Add("key1", new List<int> { 1,2,3,4,5});
ConcurrentDictionary<string, List<int>> filteredResults = new ConcurrentDictionary<string, List<int>>();
foreach (KeyValuePair<string, List<int>> unfilteredResult in unfilteredResults)
{
foreach (int number in unfilteredResult.Value)
{
if (filter.Contains(number))
{
filteredResults.AddOrUpdate(unfilteredResult.Key, new List<int> { number }, (k, v) => v.Add(number));
}
}
}
}
}