From: AMP on 30 Apr 2010 19:19 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
From: Mr. Arnold on 30 Apr 2010 19:51 AMP wrote: > 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.
From: AMP on 30 Apr 2010 19:55 On Apr 30, 7:19 pm, AMP <ampel...(a)gmail.com> wrote: > 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?
From: AMP on 30 Apr 2010 20:11 On Apr 30, 7:55 pm, AMP <ampel...(a)gmail.com> wrote: > On Apr 30, 7:19 pm, AMP <ampel...(a)gmail.com> wrote: > > > 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
From: Harlan Messinger on 30 Apr 2010 21:14 AMP wrote: > On Apr 30, 7:19 pm, AMP <ampel...(a)gmail.com> wrote: >> 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"];
|
Pages: 1 Prev: My website not running after I publish Next: css: knowing how much room to leave for text? |