Property called this

  • Thread starter Thread starter AMP
  • Start date Start date
A

AMP

Hello,
I have the following code I'm trying to follow:

......................
public string this[string propName]
{
get {...........................


How do you have, amd how do you call a property called "this"?
Thanks
 
AMP said:
Hello,
I have the following code I'm trying to follow:

.....................
public string this[string propName]
{
get {...........................


How do you have, amd how do you call a property called "this"?
Thanks

this.this if called within the class or classname/objectname.this if
property is being accessed outside the class.
 
Hello,
I have the following code I'm trying to follow:

.....................
public string this[string propName]
{
get {...........................

How do you have, amd how do you call a property called "this"?
Thanks

I found it, but I'm not sure WHY in the docs "Item" becomes "this"?
why cant we just use Item?
 
Hello,
I have the following code I'm trying to follow:
.....................
public string this[string propName]
{
get {...........................
How do you have, amd how do you call a property called "this"?
Thanks

I found it, but I'm not sure WHY in the docs "Item" becomes "this"?
why cant we just use Item?

The docs I'm trying to understand.
http://msdn.microsoft.com/en-us/library/system.componentmodel.idataerrorinfo.item.aspx
 
AMP said:
Hello,
I have the following code I'm trying to follow:

.....................
public string this[string propName]
{
get {...........................

How do you have, amd how do you call a property called "this"?
Thanks

I found it, but I'm not sure WHY in the docs "Item" becomes "this"?
why cant we just use Item?

This "this" construction is called an "indexer", and its purpose is not
mainly so you can refer to things using the word "this" or the word
"Item", but so you can use square brackets to treat objects of your
class as indexed collections (arrays, lists, whatever), setting or
getting items using array-like syntax.

public class Translator
{
...
public string this[string word]
{
get {...} set {...}
}
|

Elsewhere:

Translator englishToFrench = new Translator();
...
englishToFrench["book"] = "livre";
englishToFrench["car"] = "voiture";
...
string carInFrench = englishToFrench["car"];
string treeInFrench = englishToFrench["tree"];
 
Back
Top