【发布时间】:2012-10-07 05:10:05
【问题描述】:
我已经发布了相关问题如下:
replace 3 levels of nested for loops by efficient code possibly linq
但由于我不擅长 Linq 或 Lambda 表达式。我不知道如何进一步扩展它。
我有一个稍微不同的 3 级嵌套 for 循环,我不知道如何将其转换为 Linq 或 Lambda 表达式。我的任务是为 linq 或以下内容提供更有效的替换代码lambda表达式..请帮忙。谢谢..
public static void CompareEntities(
out EntityCollection<StringResourceEntity> entitiesDifference,
EntityCollection<StringResourceEntity> entitiesLargerSet,
EntityCollection<StringResourceEntity> entitiesSmallerSet)
{
var diff = new EntityCollection<StringResourceEntity>();
string defaultCulture = LocalizationConfiguration.DefaultCulture;
foreach (StringResourceEntity entityLargerSet in entitiesLargerSet)
{
bool entityMatch = false;
foreach (StringResourceEntity entitySmallerSet in entitiesSmallerSet)
{
if (entityLargerSet.Key.Equals(entitySmallerSet.Key))
{
foreach (var stringResValSmall in entitySmallerSet.StringResourceValues)
{
if (stringResValSmall.Culture.Equals(defaultCulture) &&
stringResValSmall.Value.Length > 0)
{
entityMatch = true;
}
}
}
}
if (entityMatch == false)
{
diff.Add(entityLargerSet);
}
}
entitiesDifference = diff;
}
【问题讨论】: