Although you can utilize the Item property, why can't you do it by
actually calling the property directly?
Calling the property directly in syntax is unsupported for the same reason
as get_Item(..) is unsupported. It is a "language feature" and boxes the
coders into a common coding convention.
In C# the parameterized Item property is reserved specifically for indexers,
and Item[..] (VB.NET) / this [..] (C#) / get_Item (MSIL) is the only indexer
property that C# uses. VB.NET supports parameterization for any custom
properties besides Item, but C# only supports the one property, which in
code is "this[..]" and not "Item[..]", but in MSIL is always
get_Item(..)/set_Item(.., ..). It is indeed a language limitation, but I
consider the limitation an intended one, which makes it a feature. It makes
it much less difficult to get confused about whether you're accessing an
object's indexer or an object's property's indexer, i.e. ...
myObject.myIndexedProp["three"]
.... is "myIndexedProperty" above implemented as an indexed myIndexedProp
property of myObject, or is it the Item property of an object that is
returned by a non-indexed myIndexProp property of myObject??
By forcing C# to use only one optional property as an indexed property,
understanding the code becomes significantly less ambiguous and awkward.
Exposing that single indexed property as "this[...]" made the property bound
to the object by its explicit name. By compiling down to MSIL as
get_Item(..)/set_Item(..) (the same MSIL method names that are used by
VB.NET's Item property), the property became inline with industry common
naming conventions for collection indexers and ultimately VB.NET coders can
then call C#'s clean "object[...]" indexer as "object.Item[...]" which is
more familar with the VB coder community anyway.
Jon
Scott M. said:
Well, I guess this is where my confusion lies. I must not fully
understand indexers, because you claim it is the answer to my question,
but I don't see how.
My question is: If the object has an Item property, then why can't you
call it (and by call it, I mean literally state the Item property in code)
in C#? You say the answer is because C# uses indexers, but it seems to me
that indexers just allow you to use the indexed property as a default
property (which is the same in VB.NET - - You don't *have* to actually
state the Item property). So, I guess I need to restate my question....
Although you can utilize the Item property, why can't you do it by
actually calling the property directly?
Jon Davis said:
Jon Davis said:
The use of the Item property is supported.
But the OP says it doesn't work in C#?
And as I said, it works--you can get the data out of the Item property
from C# where the Item property is defined in VB.NET--but the C# syntax
to do so uses the indexer syntax.
Jon
.. said syntax is "object[..]" rather than "object.Item[..]".
As far as I'm concerned, C# indexers and the Item property are one and
the same, just different nomenclature and calling syntax per language.
Jon