c# – 如何获得一个字典类型的TKey和TValue的类型
发布时间:2020-12-15 03:55:46 所属栏目:百科 来源:网络整理
导读:我想要获得TKey和TValue的类型,给出一个字典 TKey,TValue类型. 例如.如果类型为Dictionary Int32,String我想知道如何得到 keyType = typeof(Int32)和 valueType = typeof(String) 解决方法 我认为这可能是你正在寻找的: Dictionaryint,string dictionary =
我想要获得TKey和TValue的类型,给出一个字典< TKey,TValue>类型.
例如.如果类型为Dictionary< Int32,String>我想知道如何得到 解决方法
我认为这可能是你正在寻找的:
Dictionary<int,string> dictionary = new Dictionary<int,string>(); Type[] arguments = dictionary.GetType().GetGenericArguments(); Type keyType = arguments[0]; Type valueType = arguments[1]; 参考:Type.GetGenericArguments (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |