开发者

Common type for generic classes of different types

开发者 https://www.devze.com 2022-12-26 15:42 出处:网络
I have (for example) Dictionary of different generic types (d1, d2, d3, d4) and I want to store them in something

I have (for example) Dictionary of different generic types (d1, d2, d3, d4) and I want to store them in something

        var d1 = new Dictionary<in开发者_如何学JAVAt, string>();
        var d2 = new Dictionary<int, long>();
        var d3 = new Dictionary<DateTime, bool>();
        var d4 = new Dictionary<string, object>();


        var something = ???  //new List<object> {d1, d2, d3, d4};

Is there any other way how to store that in something with common denominator different than object?

Thanks :-)


You can use List<IDictionary> since Dictionary<K,V> implements IDictionary.

Alternatively, you could also use either ICollection or IEnumerable since they are also both interfaces implemented by the generic dictionary collection.

0

精彩评论

暂无评论...
验证码 换一张
取 消