c# - Get dictionary key if value contains string -
i have dictionary:
static dictionary<int, string> players = new dictionary<int, string>(); dictionary.add(1, "chris [gc]"); dictionary.add(2, "john"); dictionary.add(3, "paul"); dictionary.add(4, "daniel [gc]");
i want key of values contains "[gc]"
any idea how?
thanks.
use query below.
var itemswithgc = dictionary.where(d => d.value.contains("[gc]")).select(d => d.key).tolist(); foreach (var in itemswithgc) { console.writeline(i); }
Comments
Post a Comment