我有问题要弄明白这个问题.
我有一个通用的方法,可以给出Action<T>
来处理一些事情.但我不能将这个对象转换为T.
public interface T1 { }
public interface A : T1
{
void A1();
}
public interface B : T1
{
void A1();
}
public class Test : A, B
{
void A.A1()
{
Console.WriteLine("A");
}
void B.A1()
{
Console.WriteLine( "B");
}
public void T100<T>(Action<T> call) where T : T1
{
call((T)this); // error comes from here
}
}
这个代码有什么问题?
请告诉我,我怎样才能创造出像上面这样的东西.