More on properties: parameterful properties
Before going on, I’d like to express my condolences to everyone who lost someone on the 20th February floods which hit us a year ago. Yes, it’s been a year, but I believe that this date will never be forgotten by any of us that were here at the time…
In the last technical post,I as talking about properties. And today,we’ll keep looking at them and we’ll talk about parameterful properties. Parameterful properties (a name which I’ve borrowed from Jeff Richter’s excellent CLR via C#) are properties whose get methods accept one or more parameters and whose set methods accept two or more parameters. In C#, these properties are known as indexers and are exposed as array-like properties. The next snippet shows how one can define a parameterful property and use it from C#:
In the previous example(built only for demon purposes) ,the paramertul property expects only one parameter in the getter and two in the setter (in the previous case, the first parameter passed to the getter and setter identifies the position and the second parameter ,passed only to the setter and introduced through the “hidden” value parameter, indicates the value that is supposed to be put into that position). As you can see, this is used as special name for a parameterful property. In practice, this means that you cannot use static parameterful properties in C# (even though the CLR does support that).The previous snippet shows some interesting recommendations too: for instance, notice that we’re throwing an exception when someone passes and indexer out of the expected interval.
Another interesting feature of parameterful properties is overriding: unlike parameterless parameters, you can override them by using different parameters. Form the CLR point of view, parameterful properties will also give place to setter and getter methods. In the previous example, that means that the code we’ve written will be transformed into something which looks like this:
As you can see, the compiler will automatically pick the name Item for a parameterful property and will prepend the getter and setter methods with the get_ and set_ prefix.
In C#, we never use the name Item when consuming a parameterful property (the  operator is used instead). However, if you’re writing a library that will be consumed from other CLR languages, then you can customize the name of this property by using the IndexerNameAttribute:
By doing this, the compiler will automatically ge
nerate a pair of methods named get_Integer and set_Integer,
allowing other languages (ex.:VB.NET) to access this property through the Integer name. Notice that the String type uses this attribute to let you access a char in a string from languages which don’t use the  operator to interact with parameterful properties. Since you don’t use a name to refer to a indexer in C#, you’ll only be able to introduce one property of this “type” in your C# code (though, as I’ve mentioned previously, you can override it). This behavior might introduce some problems when you’re trying to consume in C# a type written in another language which defines more than one parameterful property. For that type to be consumed from C#, it must indicate the name of the default parameterful property through the DefaultMemberAttribute (notice that the C# compiler does this automatically for you C# types and it does takes into account the use of the IndexerNamAttribute). And yes, that will be the only parameter that C# code will be able to access…
btw, and before you ask, languages which don’t support parameterful properties can access them through direct getter and setter method calls. And that’s it for now. Stay tuned form more.