Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select all keys except some key

I Only know one key from dictionary and I want to Select all other key that are present.

I don't want to remove the KeyValue pair that I know but want to select rest.

For example, I have:

Key:Health
Value: 123

Key:Vision
Value: 345

Key:Dental
value:567

and I know that Health will be there. So I want to select all other Keyvalue pairs except Key:Health

Could any one suggest a C# code to implement this ?

like image 796
siddharth Avatar asked Mar 08 '26 11:03

siddharth


1 Answers

var allKeyValuesButHealth = dict.Where(kv => kv.Key != "Health");

Since this is a deferred executed LINQ query it's a good idea to materialize it with ToList, ToArray or even ToDictionary if you want to use it multiple times.

like image 113
Tim Schmelter Avatar answered Mar 10 '26 23:03

Tim Schmelter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!