Self referencing interface

后端 未结 4 1959
眼角桃花
眼角桃花 2021-01-18 05:15

This is the kind of thing I want to do:

Interface IMyInterface
{
    List GetAll(string whatever)
}

so that classes imp

4条回答
  •  爱一瞬间的悲伤
    2021-01-18 05:33

    This works for me:

    public interface IMyInterface
    {
        List GetAll(string whatever);
    }
    
    public class Program : IMyInterface
    {
        public string Member { get; set; }
    
        public List GetAll(string whatever)
        {
            return new List()
                { new Program() { Member = whatever } };
        }
    
        static void Main(string[] args)
        {
            List all = new Program().GetAll("whatever");
            Console.WriteLine(all.Count);
        }
    }
    

提交回复
热议问题