public class MyClass<T>
{
public T this[int index]
{
get
{
...
}
set
{
...
}
}
public void MyMethod<T>()
{
int middleIndex = ...;
T value = this[middleIndex ];
...
}
}
由於MyMethod()中的語句,代碼無法編譯。是否有另一種調用索引器的方式?從相同(通用)類中調用索引器
編輯:修飾的MyMethod()
EDIT2:編譯錯誤
Error 6 Cannot implicitly convert type 'T [C:\MyClass.cs]' to 'T [C:\MyClass.cs]'
感謝。
我
'MyMethod'中定義的'index'在哪裏? – Larsenal 2010-09-08 18:48:11
如果我用「public void MyMethod(int index)」替換MyMethod,那麼這個例子編譯得很好。 – 2010-09-08 18:49:00
你發佈的代碼看起來很好。你能發佈更多'MyMethod'嗎? – Larsenal 2010-09-08 18:49:44