I want to get type of TKey and TValue given a Dictionary<TKey,TValue> type.
Dictionary<TKey,TValue>
eg. If type is Dictionary<Int32,String> I want to know how to get keyType = typeof(Int32) and valueType = typeof(String)
Dictionary<Int32,String>
I think this may be what you are looking for:
Dictionary<int, string> dictionary = new Dictionary<int, string>(); Type[] arguments = dictionary.GetType().GetGenericArguments(); Type keyType = arguments[0]; Type valueType = arguments[1];
Ref: Type.GetGenericArguments
1.4m articles
1.4m replys
5 comments
57.0k users