コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【C#】シーケンスが空かどうかを返す拡張メソッド

ソースコード

using System.Collections.Generic;
using System.Linq;

public static class IEnumerableExtensions
{
    public static bool IsEmpty<TSource>(
        this IEnumerable<TSource> source
    )
    {
        return !source.Any();
    }
}

使い方

var array = new int[ 0 ];
if ( array.IsEmpty() )
{
}

関連記事