LINQ ElementAt and ElementAtOrDefault(codeforeternity.com)
submitted by
xtremebiz(575) 3 years, 9 months ago
We can use the ElementAt extension method of LINQ to return the element at a specified index (zero based) in a sequence. However the ElementAt extension method would throw the System.ArguementOutOfRangeException when the specified index is a negative value or not less than the size of the sequence. In such a scenario, we can use the ElementAtOrDefault extenion method which would return the default value of a type instead of throwing the System.ArguementOutOfRangeException.
Read this article for code example (both in C# and VB.NET) with comments
|category: C#
|Views: 79
tags:
LINQ .net3.5 3.5 C# VB.NET another
Everyones tags:
Your Tags: