コガネブログ

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

【C#】引数にnullを渡してもエラーにならないContainsKeyの拡張メソッド

ソースコード

using System.Collections.Generic;

public static class DictionaryExtensions
{
    public static bool ContainsKeyNullable<TKey, TValue>( 
        this Dictionary<TKey, TValue> self, TKey key 
    )
    {
        if ( key == null )
        {
            return false;
        }
        return self.ContainsKey( key );
    }
}

関連記事