har*_*sha 15 c# generics reflection
我想得到一个类型的TKey和TValue Dictionary<TKey,TValue>类型.
例如.如果type是Dictionary<Int32,String>我想知道如何获取keyType = typeof(Int32)和valueType = typeof(String)
Fre*_*örk 41
我想这可能就是你要找的东西:
Dictionary<int, string> dictionary = new Dictionary<int, string>();
Type[] arguments = dictionary.GetType().GetGenericArguments();
Type keyType = arguments[0];
Type valueType = arguments[1];
Run Code Online (Sandbox Code Playgroud)