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

后端 未结 6 1269
我在风中等你
我在风中等你 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条回答
  •  -上瘾入骨i
    2020-12-24 12:54

    You don't constrain T in the private member; you constrain it at the class level.

    class Foo where T : BaseClass
    {
        private IDictionary> _dataOfType;
    
        public Foo(IDictionary> dataOfType)
        {
            this._dataOfType = dataOfType;
        }   
    }   
    

提交回复
热议问题