Dictio是Dictionary<string, Grouped>
。
Grouped是一个包含任务列表的类。
我想根据2个参数“name”和“computerName”选择一个任务。 作为返回值,我想要一个任务对象(名称+ computerName给出1个任务)
我的代码:
var task = Dictio
.Select(s => s.Value.Tasks.Where(( z => z.Name == task.Name &&
z.ComputerName == task.ComputerName )));
答案 0 :(得分:1)
var name = "SomeName";
var computerName = "ComputerName";
var tasks = Dictio.SelectMany(s => s.Value.Tasks) // flatten all tasks to one list
.Where(z => z.Name == name && z.ComputerName == computerName )); // query
// tasks will be a list of tasks, if you want only one of them:
var task = tasks.FirstOrDefault();
// task will be the first found task or null if no task matched your query