I'd like to accomplish something like the following:
(clientSinceChoices = Enumerable.Range(1949, DateTime.Now.Year - 1950)
.Select(x => new SelectListItem()
{
Text = x != 1949 ? x.ToString() : "Unselected",
Value = x != 1949 ? new DateTime(x, 1, 1).ToString() : null,
Selected = () =>
{
if (x == 1949 && !ClientSinceYearOnly.HasValue)
return true;
else if (ClientSinceYearOnly.Value == x)
return true;
else
return false;
}
}));
I want the value of Selected to be the result of the labmda expression that is defined inline. I know I can accomplish this by assigning the lambda to a variable and then invoking it, but I think that defining and immediately invoking it is "cleaner".