是否可以使用三元运算符来反映这种逻辑?
if (a = 1)
{
somevalue = "hello";
}
else if (a = 2)
{
someValue = "world";
}
else if (a = 3)
{
someValue = "hellWorld";
}
我在 LINQ 查询中执行以下操作:
using (var data = new DAL())
{
var result = data.Holidays.AsNoTracking()
.Where(x => x.RequesterId == userId)
.Select(x => new HolidayModel
{
HolidayId = x.HolidayId,
FromDate = x.FromDate,
ToDate = x.ToDate,
AuthorisationStatus = x.InternalHolidayStatus == 1 ?
HolidayAuthStatus.Pending :
HolidayAuthStatus.Rejected,
DateModified = x.ModifiedDate
}).ToList();
return Json(result.ToDataSourceResult(request));
}
HolidayAuthStatus
是一个枚举,其中包含三个值(Pending
(1)、Authorised
(2)和Rejected
(3));我想在分配AuthorisationStatus
.