Rajesh kumar’s Blog

If you have knowledge, let others light their candles at it.

Difference between Property and Indexer in C#

Posted by Rajesh Kumar on April 16, 2009

Indexers are like properties. Except for the differences shown in the following table, all the rules that are defined for property accessors apply to indexer accessors also.

 

Actual Difference are:

Property

Indexer

Allows methods to be called as if they were public data members.

Allows elements of an internal collection of an object to be accessed by using array notation on the object itself.

Accessed through a simple name.

Accessed through an index.

Can be a static or an instance member.

Must be an instance member.

A get accessor of a property has no parameters.

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

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

A set accessor of an indexer has the same formal parameter list as the indexer, and also to the value parameter.

Supports shortened syntax with Auto-Implemented Properties (C# Programming Guide).

Does not support shortened syntax.

3 Responses to “Difference between Property and Indexer in C#”

  1. AnnaHopn said

    Hi,
    Where are you from? Is it a secret? :)
    Thanks
    AnnaHopn

  2. vsyahalava said

    Всем, всем, всем Доброе утро! Заходите на всяхалява.рф – лучший сайт халявы.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.