C# 3.0 执行以下程序(c3.0)的更好方法是什么

C# 3.0 执行以下程序(c3.0)的更好方法是什么,c#-3.0,C# 3.0,考虑下面的程序 private static bool CheckFactorPresent(List<FactorReturn> factorReturnCol) { bool IsPresent = true; StringBuilder sb = new StringBuilder(); //Get the exposure names from Exposure list. //Since this will remain same , s

考虑下面的程序

private static bool CheckFactorPresent(List<FactorReturn> factorReturnCol)
{
    bool IsPresent = true;
    StringBuilder sb = new StringBuilder();

    //Get the exposure names  from Exposure list.
    //Since this will remain same , so it has been done outside the loop

    List<string> lstExposureName = (from item in Exposures
                    select item.ExposureName).ToList<string>();


    foreach (FactorReturn fr in factorReturnCol)
    {
    //Build the factor names from the ReturnCollection dictionary
    List<string> lstFactorNames = fr.ReturnCollection.Keys.ToList<string>();

    //Check if all the Factor Names are present in ExposureName list
    List<string> result = lstFactorNames.Except(lstExposureName).ToList();

    if (result.Count() > 0)
    {
        result.ForEach(i =>
        {
        IsPresent = false;
        sb.AppendLine("Factor" + i + "is not present for week no: " + fr.WeekNo.ToString());        
        });
    }

    }
    return IsPresent;
}
基本上,我正在检查是否所有的FactorNames[lstfactrnames]都存在于

ExposureNames[LSExposureName]使用lstFactorNames.ExcepltsExposeRename列出

然后,如果Count>0,则使用Count函数写入错误

发送到字符串生成器B的消息

我相信有人一定能编写出比本文介绍的更好的实现

我也期待着从这个项目中学到新的东西

我正在使用c3.0和dotnet framework 3.5


谢谢

除了一些命名约定问题,我想说的是,这看起来很好,因为我不需要看到代码的其余部分,也不需要了解工作的目的。不过,命名约定还需要一些工作。ntnHungarian病毒、PascalCase病毒、camelCase病毒和abbrv病毒的零星混合有点让人迷失方向。试着只将局部变量命名为camelCase,情况会好得多。祝你好运-到目前为止一切看起来都很好

-编辑- 此外,您可以在最后通过运行简单的foreach来清理迭代:


你试过什么了?为什么用Stringbuilder创作而不做任何事情?这与上次编辑之前的问题有关吗?
...
foreach (var except in result)
{
    isPresent = false;
    builder.AppendFormat("Factor{0} is not present for week no: {1}\r\n", except, fr.WeekNo);
}
...