views:

73

answers:

2

Incase of Default or Empty i want to supply some value

string[] str = {string.Empty, "hello", "world" };

var select = str.Select(s => s).DefaultIfEmpty("nodata");

GridView1.DataSource = Select;
GridView1.DataBind();

why did not my grid fill with

nodata
hello
world

instead i receive

hello
world
A: 

Default if empty is used to do outer joins. Try this...

  var select = str.Select(s => String.IsNullOrEmpty(s) ? "nodata" : s);
Paul Creasey
+6  A: 

DefaultIfEmpty supplies a default value if the sequence is empty - you are trying to use it to substitute empty values in the sequence (i.e. string.Empty). You should use:

var select = str.Select(s => String.IsNullOrEmpty(s) ? "nodata" : s);
Lee
+1. Ah yes. I didn't see the default or empty requirement bit!
RichardOD