[英]C# How to make Dictionary<Type,Generic<Type>>?
I would like to make dictionary which stores different Types and generic class which uses this Type.我想制作存储不同类型的字典和使用此类型的通用 class。 How can I do such thing so each entry can be other type and get corresponding generic class as value?
我该如何做这样的事情,以便每个条目都可以是其他类型并获得相应的通用 class 作为值?
Dictionary<Type, dynamic> generics = new Dictionary<Type, dynamic>()
{
{typeof(string), new List<string>() {"test"}},
{typeof(int), new List<int>(){ 0 }}
};
foreach (Type genericsKey in generics.Keys)
{
foreach (dynamic element in generics[genericsKey])
Console.WriteLine(element);
}
Output: Output:
test
测试
00
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.