c# - 通用字典检索值

标签 c# .net dictionary

我有以下 C# 类:

class BatchData
{
    public string batchNumber { get; set; }
    public string processDate { get; set; }
    public int TotalRecords { get; set; }
    public int SuccessCount { get; set; }
}

和字典:

Dictionary<int, BatchData> BatchData = new Dictionary<int, BatchData>();

现在,我想搜索整个字典,看看是否有值

x

举办时间:

BatchData.batchNumber 

例如

对于整个字典,如果

BatchData.batchNumber = x

我知道Dictionary有一个方法

.contains

但我不确定如何应用它。

编辑:

BatchData.batchNumber = x

可以在字典中出现多次

最佳答案

你可以这样做:

BatchData.Values.Any(x=>x.batchNumber == "x");

例如:

Dictionary<int, BatchData> BatchData = new Dictionary<int, BatchData>();
BatchData.Add(1, new BatchData { batchNumber = "x"});
var hasX = BatchData.Values.Any(x=>x.batchNumber == "x"); //true;

关于c# - 通用字典检索值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32996343/

相关文章:

c# - C# 新手 - 尝试编写代码来执行简单的功能

.net - 如何对 IIS 中托管的此服务执行路径遍历攻击?

.net - Visual Studio 错误地报告未安装 Web 部署提供程序 (SQL Azure)

dictionary - 在 golang 中格式化 map[]

ios - 如何在我的标签中显示地址,当我在我的 map 上按下任何一个针

c# - 在跨线程 WinForm 事件处理中避免 Invoke/BeginInvoke 的困境?

javascript - cultureinfo 问题 - 添加语言

python - 尝试将名称分配给字典,python 认为我正在索引字符串

c# - 等待期间多个任务的控制流

c# - ExceptionAggregator.cs 在哪里