我想在给定 Dictionary<TKey,TValue>
的情况下获取 TKey 和 TValue 的类型类型。
例如。如果类型是 Dictionary<Int32,String>
我想知道如何获得
keyType = typeof(Int32) 和
valueType = typeof(字符串)
最佳答案
我认为这可能是您正在寻找的:
Dictionary<int, string> dictionary = new Dictionary<int, string>();
Type[] arguments = dictionary.GetType().GetGenericArguments();
Type keyType = arguments[0];
Type valueType = arguments[1];
关于c# - 如何在给定 Dictionary<TKey,TValue> 类型的情况下获取 TKey 和 TValue 的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26587501/