Рассмотрим приведенную ниже программу
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 () (если count ()> 0) , я пишу сообщения об ошибках
String Builder (sb)
Я уверен, что кто-то определенно может написать лучшую реализацию, чем представленная.
И я с нетерпением жду того жеузнайте что-то новое из этой программы.
Я использую c # 3.0 и dotnet framework 3.5
Спасибо