我希望获得Dictionary<TKey,TValue>
类型的TKey和TValue类型。
例如。如果type为Dictionary<Int32,String>
,我想知道如何获取
keyType = typeof(Int32)和
valueType = typeof(String)
答案 0 :(得分:38)
我想这可能就是你要找的东西:
Dictionary<int, string> dictionary = new Dictionary<int, string>();
Type[] arguments = dictionary.GetType().GetGenericArguments();
Type keyType = arguments[0];
Type valueType = arguments[1];