我有一本字典,其中的键类型为 Text
和 List<string>
类型的值我想测试这个字典是否包含名称为“U.R.P.S. PROVISIONNELLE”的键。
我所做的是:
Dictionary<Text, List<string>> echancierURSSAFE = new Dictionary<Text, List<string>>();
var dictionaryPROVIS = new Dictionary<string, string>();
dictionaryPROVIS.Keys.Where(key => echancierURSSAFE.Contains("U.R.P.S. PROVISIONNELLE")).ToList();
这里是 Text
类:
public class Text
{
public String Titre { get; set; }
public bool IsTitre { get; set; }
public bool IsDesignation { get; set; }
}
这里我有一个异常(exception),这种类型的字典不包含方法 contains
.那么我该如何解决这个问题呢?
最佳答案
根据您的评论,您可以尝试将 Any
与 Titre
一起使用,这将检查 Dictionary
文本的 Titre
包含任何 "U.R.P.S. PROVISIONNELLE"
echancierURSSAFE.Keys.Any(x => x.Titre == "U.R.P.S. PROVISIONNELLE");
如果你想得到所有的列表你可以使用Where
echancierURSSAFE.Keys.Where(x => x.Titre == "U.R.P.S. PROVISIONNELLE");
关于c# - 方法包含在文本列表字符串类型的字典中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53302759/