MrE*_*ndo 2 .net c# generics types type-parameter
我想知道在运行时获取定义字典的泛型参数的最佳方法是什么.
举个例子:
Dictionary<string, object> dict;
Run Code Online (Sandbox Code Playgroud)
在运行时如何才能发现键是字符串?
我不确定我是否理解你的问题,但我认为你的意思是这样的:
Dictionary<string, object> dict = new Dictionary<string, object>();
// ...
var args = dict.GetType().GetGenericArguments();
// args[0] will be typeof(string)
Run Code Online (Sandbox Code Playgroud)