It seems that you have design errors in your class if you need to do such things. however, the solution is this:
private static void Update(Dictionary<string, AudioInfo> dictionary, Func<AudioInfo, string> func) { dictionary.Clear(); foreach (AudioInfo entry in library_entries) { dictionary.Add(func(entry), entry); } }
And the following is used:
Update(years, x => x.Year);
You can also use a simpler method, instead of calling any methods that you can simply write:
years = library_entries.ToDictionary(x => x.Year, x => x);
If you do not have any events related to your dictionary.
And one more thing - you cannot add different elements with the same keys to the dictionary. In your case, it seems that you have different AudioInfo
objects with the same Year
, Genre
etc
source share