我知道good practice是使用LINQ而不是迭代循环,是否可以修改此代码以使用LINQ?

List<string> priorsLstIDs = ServiceUtil.extractColumnValuesAsStringVals(tqrPriors,Helper.STUDY_ID);
List<DateTime> priorsLstDates = ServiceUtil.extractColumnValuesAsDateTimeVals(tqrPriors, "STUDY_DATE");
List<PriorElemSt> priorsElemLst = new List<PriorElemSt>(priorsLstIDs.Count);

PriorElemSt elem;

for (int i = 0; i < priorsLstIDs.Count; i++)
{
    elem = new PriorElemSt(priorsLstIDs[i], priorsLstDates[i]);
    priorsElemLst.Add(elem);
}

return filterStudyPriors(priorsElemLst);

谢谢。

更新:可以将filterStudyPriors()方法的调用作为LINQ的一部分吗?

最佳答案

IEnumerable<PriorElemSt> priorsElemLst = priorsLstIDs.Select((s,i) => new PriorElemSt(s, priorsLstDates[i]));
return filterStudyPriors(priorsElemLst);

10-04 10:01