型を指定して TKey と TValue の型を取得したいですDictionary<TKey,TValue>
。
例えば、typeがDictionary<Int32,String>
keyType = typeof(Int32)、valueType = typeof(String)の場合、どのように取得するかを知りたいです。
ベストアンサー1
あなたが探しているのはこれだと思います:
Dictionary<int, string> dictionary = new Dictionary<int, string>();
Type[] arguments = dictionary.GetType().GetGenericArguments();
Type keyType = arguments[0];
Type valueType = arguments[1];