我有这个字典:
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]");
我想获取包含“[GC]”的值的键
知道怎么做吗?
谢谢。
最佳答案
使用 LINQ:
var result = Players.Where(p => p.Value.Contains("[GC]")).Select(p => p.Key);
关于c# - 如果值包含字符串,则获取字典键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39461362/