Tutorial by Examples: elementatordefault

var names = new[] {"Foo","Bar","Fizz","Buzz"}; var thirdName = names.ElementAtOrDefault(2); Console.WriteLine(thirdName); //Fizz var minusOnethName = names.ElementAtOrDefault(-1); Console.WriteLine(minusOnethName); //null var fifthName = names.Eleme...
ElementAt will return the item at index n. If n is not within the range of the enumerable, throws an ArgumentOutOfRangeException. int[] numbers = { 1, 2, 3, 4, 5 }; numbers.ElementAt(2); // 3 numbers.ElementAt(10); // throws ArgumentOutOfRangeException ElementAtOrDefault will return the item...

Page 1 of 1