You can have only one indexer in C#, though it can be overloaded.
That's not quite the same thing as having multiple (differently named)
properties with arguments in the same class.
You have to remember that properties in the CLI are actually methods (two
methods for each property if they are read/write) with a special meta tag
that makes them a property. In addition, one of those properties per class
can be labeled with the Default meta tag (assuming it has arguments). VB.NET
allows you to write directly to this paradigm. For each read/write property,
a method called "get_[PropertyName]" and a method called
"set_[PropertyName]" are created, and tagged as properties. Using the VB
Default keyword tags one of those properties as the default (so the compiler
understands which one you are calling if you don't use the property name,
but rather the array-style invokation). Note that VB allows you to use
either style of invokation for the default (with the name or nameless
array-style - which comes in handy when you can create more than one named
property statement with arguements). For all other (non-default) properties,
you must specify the member name.
In C#, you will always create exactly one Property (the Indexer), which
compiles to one or two underlying methods called exactly "get_Item" and
"set_Item" (depends on if it's read-only or not). You can change the
underlying method name only by using the IndexerName attribute, but I think
that's rather silly. At any rate, you can overload this property with as
many formal argument lists as you want, but you cannot create a seperate
named Property with an arguement list in the same class.
Just seems a little ironic that VB, (usually the more abstract and removed
syntax) in this case actually reads closer to what the underlying IL
produces and gives you the fully-functional deal, while C# is more limited
and demands bizzar syntax on top of it (for no good reason that I can come
up with). In VB, it's pretty straight-forward - all properties can have zero
or more arguments. This is consistant and easy to remember. In C#, only the
Indexer can have properties, and it's written differently from all other
properties.
-Rob Teixeira [MVP]
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<"Rob Teixeira [MVP]" <RobTeixeira@@msn.com>> wrote: Actaully, VB supports Properties with arguments, which is in fact, far
more flexible than Indexers - because you can have more than one per class
for starters.
You can have more than one indexer per class in C#. You just can't have
more than one indexer with the same parameters signature.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too