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
Post a Comment