c# - 方法包含在文本列表字符串类型的字典中

标签 c# asp.net

我有一本字典,其中的键类型为 TextList<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 .那么我该如何解决这个问题呢?

最佳答案

根据您的评论,您可以尝试将 AnyTitre 一起使用,这将检查 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/

相关文章:

c# - 提交表单时不调用 Controller 函数

c# - 空操作 lambda

C# 集合类型约束泛型

c# - 性能:在 VS 中编译,在 Windows 和 Linux 上以 Mono 运行

c# - WCF服务和AJAX调用问题

c# - 执行服务器端 XML 处理时出错

c# - View 中的 2 个按钮在 asp.net mvc 中执行不同的操作

c# - SignalR - Websockets - 超出缓冲区长度

c# - 使用正则表达式删除字典条目

c# - 在gridview中格式化十进制值