There are plenty of other members that could be parameterized.
However, there are no generic properties, indexers, operators, constructors, finalizers,
or events. First let??™s be clear about what we mean here: clearly an indexer can have
a return type that is a type parameter??”List
is an obvious example. KeyValue-
Pair provides similar examples for properties. What you can??™t have is
an indexer or property (or any of the other members in that list) with extra type
parameters. Leaving the possible syntax of declaration aside for the minute, let??™s look
at how these members might have to be called:
SomeClass instance = new SomeClass("x");
int x = instance.SomeProperty;
byte y = instance.SomeIndexer["key"];
instance.Click += ByteHandler;
instance = instance + instance;
I hope you??™ll agree that all of those look somewhat silly. Finalizers can??™t even be called
explicitly from C# code, which is why there isn??™t a line for them. The fact that we can??™t
do any of these isn??™t going to cause significant problems anywhere, as far as I can
see??”it??™s just worth being aware of it as an academic limitation.
The one exception to this is possibly the constructor. However, a static generic
method in the class is a good workaround for this, and the syntax with two lists of type
arguments is horrific.
Pages:
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232