鉴于以下课程...
public abstract class FooBase<TBar> where TBar : BarBase{}
public abstract class BarBase{}
public class Bar1 : BarBase{}
public class Foo1 : FooBase<Bar1> {}
...以及以下方法...
public TBar DoSomething<TFoo, TBar>(TFoo theFoo)
where TFoo : FooBase<TBar>
where TBar : BarBase
{
return default(TBar);
}
为什么以下代码行不能暗示返回类型?
Bar1 myBar = DoSomething(new Foo1());
相反,我必须指定这样的泛型类型......
Bar1 myBar = DoSomething<Foo1, Bar1>(new Foo1());