c# 4.0 - Can we use DefaultIfEmpty to show a default image? -


i have album task need show images db. supposing there no matching image in db, can use defaultifempty select default image?

edit: defaultifempty has suitable overload.

you can't provide default value firstordefault() use:

// select first image, or default otherwise var image = query.firstordefault() ?? defaultimage; 

or write own overload of firstordefault does accept default, of course. this:

public static t firstordefault<t>(this ienumerable<t> source,     t defaultvalue) {     // ever iterate once, of course.     foreach (t item in source)     {         return item;     }     return defaultvalue; } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -