Then we define a list
of items, which is an empty collection. After that, we try to enumerate through the
object collection using DefaultIfEmpty. The defaultItem argument used for the
operator, means that the default item defined is considered if the original sequence
is empty.
Item defaultItem = new Item {Category="Icecreams", Name="Default
Item Test", Ingredients="cream, milk, ...", Cholesterol="50mg",
Protein="4g", TotalCarbohydrates="35g", TotalFat="20g", Price=10.5
, FatContents = new FatContent{SaturatedFat="6g", TransFat="4g",
OtherFat="6g"} };
List
- items = new List
- ();
foreach (Item itm in items.DefaultIfEmpty(defaultItem))
Console.WriteLine("{0}", itm.Name);
An ArgumentNullException is thrown if the source argument is null.
ElementAt
This operator returns an element at a specified index in a sequence. It skips all the
elements until the index is specified, and then returns the element from the specified
index. If the source sequence implements IList, the implementation is used for
retrieving the element at the specified index.
Pages:
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314