嘿,我想知道我正在尝试做的事情是否可能?代码中的注释应该能够说明我要实现的目标 :)
interface ITest<T> {
T t { get; }
bool DoTest();
}
public abstract class Test<T> : ITest<T> {
public Test (T nt) {
this.t = nt;
}
public Test () {
}
public T t {
get;
private set;
}
public abstract bool DoTest ();
}
public class STest : Test<string> {
public override bool DoTest () {
return true;
}
}
public class ITest : Test<int> {
public override bool DoTest () {
return true;
}
}
public class TestTest {
// I don't want to specify type here, I'd like TestTest to be able to have
// either a ITest or a STest. But for this class it should not matter.
// I just want to use DoTest() later on. No matter what
// specialication of Test this is.
Test myTest;
}
这可能是一个设计问题,如果是的话,我愿意重新考虑 :)
StringTest
/IntTest
并且这样会更容易阅读时,也不建议将其称为STest
/ITest
。 - Timwi