我正在尝试将我的genric功能拉到基类,但是不同的数据类型阻止我这样做。请参阅:
public class OutWriter
{
private readonly IEnumerable<long> series1;
private readonly IEnumerable<long> series2
private readonly IEnumerable<long> series3
private readonly IEnumerable<double> series4
private readonly double sum;
public OutWriter()
{
series1 = PopulateS1()
series2 = PopulateS2()
series3 = PopulateS3()
series4 = PopulateS4()
sum = series4.Aggregate((x,y)=>x+y);
}
}
public class PaperWriter
{
private readonly IEnumerable<BigInteger> series1;
private readonly IEnumerable<BigInteger> series2
private readonly IEnumerable<BigInteger> series3
private readonly IEnumerable<BigInteger> series4
private readonly BigInteger sum;
public PaperWriter()
{
series1 = PopulateS1()
series2 = PopulateS2()
series3 = PopulateS3()
series4 = PopulateS4()
sum = series4.Aggregate((x,y)=>x+y);
}
}
public class Base<T>()
{
????
}
我正试图提升相似之处,但涉及long
,double
和BigInteger
。此外,由于+操作,聚合会抛出编译时错误。你能告诉我怎么做得恰到好处吗?
谢谢, -Mike