比如说我写了个接口,下面有4个类实现了这个接口
这四个类反回类型为List<a>,List<b>,list<c>,List<d>,那在接口中要怎么声明list<>啊,调用接口时要怎么用啊?求助

解决方案 »

  1.   

    不太明白楼主的意思 是不是List<T>?
      

  2.   

    例如
    public interface IBehavior<T>
    {
        public List<T> Value{get;set;}
    }public class BehaviorInt : IBehavior<int>
    {
    }
    public class BehaviorString : IBehavior<string>
    {
    }
      

  3.   

    [code=C#]
    interface IL<T>
    {
        List<T> GetList();
    }class A : IL<A>
    {
        public List<A> GetList()
        {
            return ...;
        }
    }
    code]
      

  4.   

    List<object> 可以实现,但是是最糟糕的一种做法
    楼主可以使用泛型来实现例一:
    interface ITest
        {
            IList<T> Method<T>();
        }
    例二:
    interface ITest<T>
        {
            IList<T> Method();
        }