C#在运行时获取定义字典的类型 [英] C# get the types defining a Dictionary at run time
本文介绍了C#在运行时获取定义字典的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
举个例子:
$ b 我想知道获取运行时定义字典的泛型参数的最佳方法是什么。$ b
字典< string,object>快译通;
在运行时,我可以发现键是字符串吗?
pre>
字典< string,object> dict = new Dictionary< string,object>();
// ...
var args = dict.GetType()。GetGenericArguments();
// args [0]将是typeof(string)
I was wondering what is the best way for getting the generic arguments that definine a dictionary at run time is.
Take for example:
Dictionary<string, object> dict;
How at runtime can I find out that the keys are strings?
解决方案
I'm not sure if I understand your question correctly but I think you mean something like this:
Dictionary<string, object> dict = new Dictionary<string, object>();
// ...
var args = dict.GetType().GetGenericArguments();
// args[0] will be typeof(string)
这篇关于C#在运行时获取定义字典的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文