在我的代码,我有“sourceElements”是一种类型的使用“包含”查询在C#中的列表<Key-Value>
List<KeyValuePair<string, string>>.
我需要查询,如果该列表的键包含特定值,i尝试这样:
sourceElements.Add(new KeyValuePair<string, string>("t","t"));
sourceElements.Add(new KeyValuePair<string, string>("test", "test"));
sourceElements.Add(new KeyValuePair<string, string>("t1", "t2"));
if (sourceElements.All(x => x.Key.Contains("test", StringComparer.InvariantCultureIgnoreCase))
{
// do some stuff here
}
但是编译器报告“类型参数不能从使用推断”。
任何想法在代码中不正确的东西?
您正在检查一个布尔值为“0”。 '.contains'将返回'true'或'false' – NoLifeKing
@NoLifeKing:yup。改变了! –
是否可以将数据结构更改为'Dictionary'而不是? –
NoLifeKing