以下の内容はhttps://baba-s.hatenablog.com/entry/2022/09/12/140716より取得しました。


【C#】TryElementAt 拡張メソッド

ソースコード

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;
        }
    }
}



以上の内容はhttps://baba-s.hatenablog.com/entry/2022/09/12/140716より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14