Tuesday, March 17, 2009

properties and indexers in C#?

what are properties and indexers in C#?
Properties are known as smart fields and enable access to the fields of a class. Indexers are also called smart arrays in C# and can be used to use an object as an array. Properties are accessed by names but indexers are accessed using indexes.

Properties can be static but we cannot have static indexers. Indexers should always be instance members of the class. The get accessor of a property does not accept any parameter but the same of the indexer accepts the same formal parameters as the indexer. The set accessor of a property contains an implicit parameter called "value".The set accessor of an indexer contains the same formal parameters as that of the indexer and also the "value" as an implicit parameter.

No comments: