Error!
Success!

LINQ ElementAt and ElementAtOrDefault

0
kicks

LINQ ElementAt and ElementAtOrDefault  (Unpublished)

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


Kicked By:
Drop Kicked By: