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 , 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 [lstFactorNames]存在於
ExposureNames [lstExposureName]列表通過使用lstFactorNames.Except(lstExposureName).
,然後通過使用所述COUNT()函數(如果計數()> 0),我寫錯誤
消息到字符串構建(SB)
我相信有人能肯定寫一個比呈現一個更好的實現。
我期待着同樣的學習新的東西。
我使用C#3.0和DOTNET框架3.5
感謝
還有,你試過嗎? – 2010-06-17 08:10:30
爲什麼創建這個Stringbuilder而不做任何事情呢? – glenatron 2010-06-17 13:41:33
這是否與最後一次編輯之前問的問題有關? – 2010-06-17 13:43:02