我正在尝试以有效的方式编写代码并实现以下目标:
抱歉,我下面的代码与我上面想要的不正确。我需要纠正以下问题的指导/帮助
public class Input
{
List<string> Description { get; set;}
}
IList<Notes> notes = GetNotes (input);
decimal noteNumber = GetTotalNumber();
List<string> channel = GetChannels();
string status = GetStatus();
DateTime date = GetDate();
foreach (var item in notes)
{
if (noteNumber == item.ConditionOne)
input.Description = item.Description;
break;
if(noteNumber == item.ConditionTwo)
input.Description = item.Description
continue with next item in Foreach list of rows
}
public class Notes
{
[DataMember]
public string Description{ get; set; }
[DataMember]
public string ConditionOne{ get; set; }
[DataMember]
public string ConditionTwo{ get; set; }
[DataMember]
public string All { get; set; }
}
您可以使用break
来跳出循环。没有理由在此处使用任何 Lambda 表达式。这很简单。添加正确的缩进并使用大括号将使其更容易理解。见下文。
foreach (var item in notes)
{
if (noteNumber == decimal.Parse(item.ConditionOne, NumberStyles.Currency))
{
// condition one - break out of loop
break;
}
if(noteNumber == item.ConditionTwo)
{
// condition two. add description to list
input.Description.Add(item.Description}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句