如何对列值执行条件选择,我对返回哪个值有偏好。如果我找不到最佳选择,我会选择下一个,如果有的话,然后如果不是下一个,等等。现在看起来,总共需要 3 个查询。有没有办法进一步简化这个?
var myResult = string.Empty;
if (myTable.Where(x => x.ColumnValue == "Three").Any())
{
myResult = "Three"; // Can also be some list.First().Select(x => x.ColumnValue) if that makes it easier;
}
else if (myTable.Where(x => x.ColumnValue == "One").Any())
{
myResult = "One";
}
else if (myTable.Where(x => x.ColumnValue == "Two").Any())
{
myResult = "Two";
}
else
{
myResult = "Four";
}