Why can't I use a compatible concrete type when implementing an interface

前端 未结 3 1084
深忆病人
深忆病人 2020-12-15 09:45

I would like to be able to do something like this :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test
{
          


        
3条回答
  •  攒了一身酷
    2020-12-15 10:07

    Although List implements IEnumerable that's not the way interfaces work. The interface specifies exactly which types need to be exposed for properties. If you created a generic interface like

    public interface IFoo where T : IEnumerable
    {
        T integers { get; set; }
    }
    

    You could then use IFoo> to implement it in the way you expect.

提交回复
热议问题