我有一个动作类型对象列表。每个对象都有一个部门列表。
我有一个用户,一个用户对象有多个部门。
我想获得用户可以采取的用户操作列表。以下是我提出的建议:
List<Item> userActions = new List<Item>();
foreach (var actionType in actionTypelist)
{
foreach (var dept in actionType.availableDepts)
{
if (data.currentUser.secondaryServDepts.Where(x => x.Id == dept.servDeptId).Count() > 0)
{
userActions.Add(actionType);
}
}
}
您能否建议更好的方法来获得更快的结果?提前谢谢。
答案 0 :(得分:0)
一种可能的优化,而不是:
...
i18nInFile?: string;
i18nInFormat?: string;
i18nOutFile?: string;
i18nOutFormat?: string;
locale?: string;
...
使用:
if (data.currentUser.secondaryServDepts.Where(x => x.Id == dept.servDeptId).Count() > 0)
{
userActions.Add(actionType);
}
Count将枚举整个集合,而Any将在第一场比赛时停止(因为你需要的只是至少一个项目)