コガネブログ

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

【C#】配列やリストが空かどうかを返す拡張メソッド

ソースコード

using System.Collections.Generic;

public static class IListExtensions
{
    public static bool IsEmpty<T>( this IList<T> self )
    {
        return self.Count == 0;
    }
}

使い方

var x = new int[ 0 ];
var y = new int[ 1 ];
x.IsEmpty(); // True
y.IsEmpty(); // False

関連記事