
Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
Thanks for the reply. I was initially thinking of indexers but I had doubts
because of the fact that there were no square brackets in the declaration
and docs clearly stated that they were properties. The link that I was
referring to is at:
http://msdn2.microsoft.com/en-us/library/system.data.common.dbparametercollectio
n.item.aspx
So, how shoud I interpret the following syntax: Item(Int32)? Is this an
indexer that can be accessed by an integer index? If yes, do C# specs have
this syntax defined somewhere?
Thanks,
Bogdan
> Bogdan,
>
[quoted text clipped - 29 lines]
>> Thanks,
>> Bogdan
jehugaleahsa@gmail.com - 23 Feb 2008 20:27 GMT
> Thanks for the reply. I was initially thinking of indexers but I had doubts
> because of the fact that there were no square brackets in the declaration
[quoted text clipped - 47 lines]
>
> - Show quoted text -
Make sure you are looking at the C# example and not the VB example.
Under the hood, C# convert all properties to methods:
<value_type> get_PropertyName
void set_PropertyName(<value_type> value)
When working with Indexers, those methods look like this:
<value_type> get_Item(<list of indices>);
void set_Item(<list of indices>, <value_type> value);
Some times when looking at a property either through a COM Interop or
through VB you will just see Item. Here you just pass the indices as
arguments. It is just like saying:
myClass[<list of indices>]
In C++, overloading the [] operator is no different, except .NET
converts it to a method call under the hood.
Am I answering your question?
Bogdan - 25 Feb 2008 03:43 GMT
[...]
>Make sure you are looking at the C# example and not the VB example.
>Under the hood, C# convert all properties to methods:
[quoted text clipped - 17 lines]
>
>Am I answering your question?
Yes. Thanks. The COM Interop was a good clue.
Nicholas Paldino [.NET/C# MVP] - 23 Feb 2008 20:36 GMT
Bogdan,
Well, an indexer is usually just shorthand for an indexed property. You
could call it directly if you wanted, but I don't see the point.
The syntax means that if you were going to access it directly by its
property, then the property you would access is the Item property. The
Int32 means that you can index it on an integer (although other collections
might be indexed on other things, in which case, that type will be where
Int32 is).
You could look in the C# programmers guide as well as the C# language
specification if you are looking for the specific definition of an indexer.
A google search will turn up both easily.

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> Thanks for the reply. I was initially thinking of indexers but I had
> doubts because of the fact that there were no square brackets in the
[quoted text clipped - 42 lines]
>>> Thanks,
>>> Bogdan
Bogdan - 25 Feb 2008 03:45 GMT
Thanks again for the reply and your patience.
I get it know. I was confusing C#'s indexers and properties with .NET
properties. I wrongly assummed that having language filter set to C# will
cause all declarations to appear in C#. So when I saw
"DbParameterCollection.Item Property" I thought that it referred to C#
property of a class.
> Bogdan,
>
[quoted text clipped - 10 lines]
> specification if you are looking for the specific definition of an
> indexer. A google search will turn up both easily.
[...]