基本上,我想做的是:
public class MySpecialCollection<T>
where T : ISomething { ... }
public interface ISomething
{
public ISomething NextElement { get; }
public ISomething PreviousElement { get; }
}
public class XSomething : ISomething { ... }
MySpecialCollection<XSomething> coll;
XSomething element = coll.GetElementByShoeSize(39);
XSomething nextElement = element.NextElement; // <-- line of interest
Run Code Online (Sandbox Code Playgroud)
...无需将nextElement转换为XSomething.有任何想法吗?我本来想要的东西......
public interface ISomething
{
public SameType NextElement { get; }
public SameType PreviousElement { get; }
}
Run Code Online (Sandbox Code Playgroud)
先感谢您!