c# - How to find key value pair in a dictionary with values > 0 with key matching a certain string pattern? -
this dictionary,
dictionary<string, uint> osomedictionary = new dictionary<string, uint>(); osomedictionary.add("dart1",1); osomedictionary.add("card2",1); osomedictionary.add("dart3",2); osomedictionary.add("card4",0); osomedictionary.add("dart5",3); osomedictionary.add("card6",1); osomedictionary.add("card7",0);
how key/value pairs osomedictionary
keys starts string "card" , has value greater zero?
var result = osomedictionary.where(r=> r.key.startswith("card") && r.value > 0);
for output:
foreach (var item in result) { console.writeline("key: {0}, value: {1}", item.key, item.value); }
output:
key: card2, value: 1 key: card6, value: 1
remember inlcude using system.linq
Comments
Post a Comment