In C#: How to declare a generic Dictionary with a type as key and an IEnumerable<> of that type as value?

后端 未结 6 1283
我在风中等你
我在风中等你 2020-12-24 12:10

I want to declare a dictionary that stores typed IEnumerable\'s of a specific type, with that exact type as key, like so: (Edited to follow johny g\'s comment)<

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-24 12:41

    Make a custom Dictionary class:

    public class BaseClassDictionary> : Dictionary>
        where T : BaseClass
    {
    }
    

    Then you can use this specialized dictionary instead as field type:

    private BaseClassDictionary> myDictionary;
    

提交回复
热议问题