いくつかのコンテキストは役に立ちますが、次のようなものがあるようです
class Foo<T> where T : Y {
object GetIndexer() { /* ... */ }
}
その場合、なぜ
SomeCollection<Y> GetIndexer() { /* */ }
そうすれば、キャストは必要ありません。
しかし、「インデクサー」という用語の使用には少し混乱しています。C# のインデクサーは、型の [] 演算子をオーバーロードする方法であるため、次のようなことができます。
MyCollectionType c = new MyCollectionType()
c["someValue"]
それらは次のように定義されます。
class MyCollectionType {
public string this [string index] // This particular indexer maps strings to strings, but we could use other types if we wished.
get {} // Defines what to do when people do myCollection["foo"]
set {} // Defines what to do when people do myCollection["foo"] = "bar"
}
型のオブジェクトはSomeCollection<Y>インデクサーではなく、コレクションです。