Comparison Between Properties and Indexers PDF Print E-mail
User Rating: / 0
PoorBest 
Saturday, 07 March 2009
HTML clipboard

Property:

-Identified by its name.

-Accessed through a simple name or a member access.

-Can be a static or an instance member.

-A get accessor of a property has no parameters.

-A set accessor of a property contains the implicit value parameter.

Indexer: -Identified by its signature.

-Accessed through an element access.

-Must be an instance member.

-A get accessor of an indexer has the same formal parameter list as the indexer.

-A set accessor of an indexer has the same formal parameter list as the indexer, in addition to the value parameter.

Indexer Declaration:

General:

accessModifier returnType this[IndexType1 indexName1,
IndexType2 indexName2, IndexType3 indexName3, .....]
{
get
{
//use indexName1, indexName2, indexName3 .. to get data
}
set
{
//use indexName1, indexName2, indexName3 .. to set data
}
}

How to Create an indexer from VS.Net:

-right click on your class name or any class you want to add an indexer inside it.

-From the (Add->) menu item choose (Add Indexer []), "Add->Add Indexer"

-Then provide your Indexer information like accessModifier, returnType & parameter List.
 

Last Updated ( Sunday, 08 March 2009 )
 
< Prev   Next >
School Joomla Templates and Joomla Tutorials