Accepted answer

You're probably looking for something like this:

var record = myList.All(m => m.Date.Equals("Never")) 
               ? myList.FirstOrDefault() 
               : myList.FirstOrDefault(m => !m.Date.Equals("Never"));

For more on .All() just look at this MSDN post.


var record = myList.FirstOrDefault(m => !m.Date.Equals("Never"))
               ?? myList.FirstOrDefault();

i.e. first one that doesn't equal never or null, and if null, just the first one (or null).


Since you have two rules, you will need an if condition somewhere.

The simplest form that I can think of is something like this:

return myList.All(x => x.Date == "Never") ? myList.FirstOrDefault() : myList.FirstOrDefault(x => x.Date != "Never");

Related Articles