我是 LINQ 的初学者。我想执行一些条件操作,如下所示,
(from emp in Employees
let DOB=emp.BirthDate.GetValueOrDefault()
let year=DOB.Year
let month=DOB.Month
let EmpAgeInYearsToday=DateTime.Now.Year-year
let EmpAgeInMonthToday=DateTime.Now.Month-month
let temp_year=(EmpAgeInYearsToday-1)
let ExactNoOfMonths_temp=EmpAgeInMonthToday<0?temp_year:EmpAgeInMonthToday
let ExactNoOfMonths=EmpAgeInMonthToday<0?EmpAgeInMonthToday+12&temp_year:EmpAgeInMonthToday
select new{emp.EmployeeID,DOB,
EmployeeAgeToday=EmpAgeInYearsToday+" Years "+ExactNoOfMonths+" Months ").Dump();
这里,
让 ExactNoOfMonths=EmpAgeInMonthToday<0?EmpAgeInMonthToday+12&temp_year:EmpAgeInMonthToday
这部分不起作用。单独 & 左侧的表达式正在执行。我想执行这两个操作。如何做到这一点?条件满足时如何进行多次操作?有没有其他替代方法可以做到这一点?