2 ms·
Though, even in C#, it would be inadvisable. If you have the same class implement both `IList<String>` and `IList<int>` you'll have some ambiguity to deal with
by bunderbunder 8y ago
Though, even in C#, it would be inadvisable. If you have the same class implement both `IList<String>` and `IList<int>` you'll have some ambiguity to deal with in implementing
object IList.this[int index] { ... }
The expectation is that that property's getter should just upcast the return value of the generic version of the indexer.
For both languages, you'd be better off having two separate methods for the two different kinds of list.
- int_19h 8y agoThe point of doing this is not to invoke these members directly on the object, though. It's to allow the object to be passed to anything that expects either IList<string> or IList<int>, or for runtime discovery purposes with is/as. Perhaps a better example is something like IConvertibleTo<T>. There's an obvious meaning to a class implementing it for many different Ts.