c# - FirstOrDefault inline null checking -


i have following code :

var result = new collection<object>();  result.add(      list.select(s => new      {           s.name,           rating = s.performance.orderbydescending(o => o.year).firstordefault().rating      }) ); 

if there's no record found in performance, give me nullexception expected because i'm trying rating property null value question how set null if firstordefault() null , rating value if not.

thanks

do this:

rating = s.performance.orderbydescending(o => o.year)                       .select(o => o.rating)                       .firstordefault() 

Comments

Popular posts from this blog

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

json - Zend error Connection -

javascript - Trigger mouseenter when an animated element touches mouse -