Given the following classes...
public abstract class FooBase<TBar> where TBar : BarBase{}
public abstract class BarBase{}
public class Bar1 : BarBase{}
public class Foo1 : FooBase<Bar1> {}
...and the following method...
public TBar DoSomething<TFoo, TBar>(TFoo theFoo)
where TFoo : FooBase<TBar>
where TBar : BarBase
{
return default(TBar);
}
Why can't the following line of code imply the return type?
Bar1 myBar = DoSomething(new Foo1());
Instead I have to specify the generic types like this...
Bar1 myBar = DoSomething<Foo1, Bar1>(new Foo1());
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…