SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 135 | Next

Scott Klein

"Professional LINQ"

Aggregate(Enumerable.Empty(),
(current, next) => next.Length > 2 ? current.Union(next) : current);
71
Part I: Introduction to Project LINQ
foreach (string item in namelist)
listBox1.Items.Add(item);
When this query is run, the following results are returned because two of the arrays have more than two
elements:
Joe
John
Jim
Josh
Joyce
Dave
Dinesh
Doug
Doyle
Change the query so that it is looking for arrays that have more than five elements, as shown below:
IEnumerable namelist = names.Aggregate(Enumerable.Empty(),
(current, next) => next.Length > 5 ? current.Union(next) : current);
When the query is run now, nothing is returned. Or better said, an empty collection is returned. You can
tell this by placing a breakpoint on the foreach statement. When the query is run, the execution does
indeed step into the foreach statement, letting you know that an empty collection was returned, but the
line that adds items to the list box is not hit or executed.
The Empty operator is basically used as a seed value for the aggregate operator if the criteria is not met.


Pages:
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6