ソースコード
using System; using System.Collections.Generic; namespace Kogane { // ReSharper disable once InconsistentNaming public static class IEnumerableExtensionMethods { public static bool TryElementAt<TSource> ( this IEnumerable<TSource> source, int index, out TSource result ) { if ( source == null ) throw new ArgumentNullException( nameof( source ) ); var i = 0; foreach ( var element in source ) { if ( i == index ) { result = element; return true; } i++; } result = default; return false; } } }