Here is a snippet of my code:
var link = socials.Where(p => p.type == Facebook).FirstOrDefault().URL;
the problem is that there aren't any social object in the list, FirstOrDefault()
return null
, and .URL
trigger an exception.
How can I avoid this in "one" line with LINQ? Thus, if null return empty ""
(or custom even better) string, else .URL
?