本文介绍了如何在lambda表达式中使用运算符(if else)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 CurrentFinancialMovementData movementData = keys.OrderByDescending(s => s.LatestReserveDate ?? s.LatestRecoveryReserveDate).ThenByDescending(x => x.ReserveDaySequence).First(); 

CurrentFinancialMovementData movementDataReserve = keys.Where(s => s.AmountType ==(short)StaticValues.AmountType.Reserve).OrderByDescending(a => a.LatestReserveDate).ThenByDescending(x => ; x.ReserveDaySequence).FirstOrDefault();

CurrentFinancialMovementData movementDataRecoveryReserve = keys.Where(s => s.AmountType ==(short)StaticValues.AmountType.RecoveryReserve).OrderByDescending(a => a.LatestRecoveryReserveDate).ThenByDescending(x => ; x.ReserveDaySequence).FirstOrDefault();





我想检查我的movingData AmountType.Reserve然后它必须采用LatestReserveDate并且如果我的movementData是AmountType.RecoveryReserve,它应该采用LatestRecoveryReserveDate。我想在movingData中处理这种情况。任何人都可以帮助我吗?



我尝试过:



我试过:

if(keys.Any(s => s.AmountType ==(short)StaticValues.AmountType.Reserve))

{CurrentFinancialMovementData movementData = keys .OrderByDescending(s => s.LatestReserveDate).ThenByDescending(x => x.ReserveDaySequence).First();

}

else if(keys.Any(s => s.AmountType ==(short)StaticValues.AmountType.RecoveryReserve))

{CurrentFinancialMovementData movementData = keys.OrderByDescending(s => s.LatestRecoveryReserveDate).ThenByDescending(x => x.ReserveDaySequence).First();

}

解决方案

CurrentFinancialMovementData movementData = keys.OrderByDescending(s => s.LatestReserveDate ?? s.LatestRecoveryReserveDate).ThenByDescending(x => x.ReserveDaySequence).First();

CurrentFinancialMovementData movementDataReserve = keys.Where(s => s.AmountType == (short)StaticValues.AmountType.Reserve).OrderByDescending(a => a.LatestReserveDate).ThenByDescending(x => x.ReserveDaySequence).FirstOrDefault();

CurrentFinancialMovementData movementDataRecoveryReserve = keys.Where(s => s.AmountType == (short)StaticValues.AmountType.RecoveryReserve).OrderByDescending(a => a.LatestRecoveryReserveDate).ThenByDescending(x => x.ReserveDaySequence).FirstOrDefault();



I want to check if my movementData AmountType.Reserve then it must take LatestReserveDate and if my movementData is AmountType.RecoveryReserve than it should take LatestRecoveryReserveDate. I want to handle this situation in movementData. Can anyone help me in this ?

What I have tried:

I tried:
if (keys.Any(s => s.AmountType == (short)StaticValues.AmountType.Reserve))
{ CurrentFinancialMovementData movementData = keys.OrderByDescending(s => s.LatestReserveDate).ThenByDescending(x => x.ReserveDaySequence).First();
}
else if (keys.Any(s => s.AmountType == (short)StaticValues.AmountType.RecoveryReserve))
{ CurrentFinancialMovementData movementData = keys.OrderByDescending(s => s.LatestRecoveryReserveDate).ThenByDescending(x => x.ReserveDaySequence).First();
}

解决方案


这篇关于如何在lambda表达式中使用运算符(if else)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 16:40