I have the following structure in my code Dictionary<TKeys, TValues> data;
. I run some LINQ queries on both data types and often need to switch between Keys
and Values
. What is the best way to get the list of Keys for given Values and vice versa? Please, notice, that I usually have 'IEnumerable' and 'IEnumerable' as a result of my previous LINQ queries and would like to have something like IEnumerable<TKeys> Dictionary.GetAllKeys(IEnumerable<IValues> vals)
and IEnumerable<TValues> Dictionary.GetAllValues(IEnumerable<IKeys> keys)
.
Maybe I need other data container for this task?
Regards, Alexander.
var values = dictionary.Where(x => someKeys.Contains(x.Key)).Select(x => x.Value); var keys = dictionary.Where(x => someValues.Contains(x.Value)).Select(x => x.Key);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With