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

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -