给定以下代码,是否可以拥有一组通用类型的项目:
public abstract class AGeneric<T> {
internal virtual List<T> MyList { get; set; }
}
public class LibA<T> : AGeneric<T> {
internal override List<T> MyList { get; set; }
}
public class LibB<T> : AGeneric<T> {
internal override List<T> MyList { get; set; }
}
public class LibC<T> : AGeneric<T> {
internal override List<T> MyList { get; set; }
}
//.
//.
//.
Main {
List<AGeneric> test = new List<AGeneric>(); //error - requires type;
List<BGeneric> test2 = new List<BGeneric>();
test2.first().
}
public abstract class BGeneric {
internal virtual List<T> MyList { get; set; } //cant use T to provide implementation
}
public class LibD<T> : BGeneric {
internal override List<T> MyList { get; set; }
}
public class LibE<T> : BGeneric {
internal override List<T> MyList { get; set; }
}
public class LibF<T> :BGeneric {
internal override List<T> MyList { get; set; }
}
目标是从抽象类中实现各种类型的 List,因为这些类的目的是确定并返回强类型对象数组。