I saw an example on MSDN where it allowed you to specify a default value if nothing returned. See below:
List<int> months = new List<int> { }; int firstMonth2 = months.DefaultIfEmpty(1).First();
Can this functionality be used with an object? Example:
class object { int id; string name; }
code:
List<myObjec> objs = new List<myObjec> {}; string defaultName = objs.DefaultIfEmpty().name;
UPDATE:
I thought I could do something like this:
List<myObjec> objs = new List<myObjec> {}; string defaultName = objs.DefaultIfEmpty(new myObjec(-1,"test")).name;
But they couldnโt. It should be noted that I'm really trying to use this method for an object defined in my DBML using LINQ-To-SQL. Not sure if it matters in this case or not.
source share