Property called this

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
 
M

Mr. Arnold

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.
 
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

I found it, but I'm not sure WHY in the docs "Item" becomes "this"?
why cant we just use Item?
 
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

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
 
H

Harlan Messinger

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"];
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top