Comparison Between Properties and Indexers
http://www.csharpfriends.com
World's Greatest C# Community    
Home Articles C# Forums Books C# Syntax C# Spec C# Jobs free Source Code Advertise About
 

Control Panel

[ Sign In / register ]
Points   
Notes 
My Forums
My Tutorials
My Profile

Resources

Learn
 Articles
 QuickStarts
 C# Spec
 Whitepapers
 Tools
 Class Browser
 C# Code Generator
 Links
 Misc Rss Feeds
 Code Highlight
 411 Directory
 FREE magazines
 freevb.net

Reviews
  ASP.NET Hosting

Source Code
 Get Version 1.0



C# Consulting
AspDotNetStoreFront
Chapter:   Indexers
Current Lesson:
Comparison Between Properties and Indexers
[Latest Content]
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | ALL
[prev. Lesson]  Using Queue class in C# [next Lesson]  Error Handling: Catching Errors With ASP.Net and C# (Part 3)
Comparison Between Properties and Indexers
  by: mosessaur

Comparison Between Properties and Indexers

by: mosessaur

Indexers permit instances of a class or struct to be indexed in the same way as arrays. Indexers are similar to properties. Except for the differences shown in the following table, all of the rules defined for property accessors apply to indexer accessors as well.

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.



For more information & examples use the keyword "indexers" to search in side MSDN

The Code: Indexers Project


1 


Build Your Own ASP.NET Website Using C# & VB.NET

Chapter:  Indexers
Current Lesson:
Comparison Between Properties and Indexers
[Latest Content]
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | ALL
[prev. Lesson]  Using Queue class in C# [next Lesson]  Error Handling: Catching Errors With ASP.Net and C# (Part 3)


Today's Top Movers
vulpes 6800
MadHatter 2220
jal 867
Jeff1203 857
muster 791

Yesterday Top Movers
shakti sin.. 9
MadHatter 3
C#fanatic 2
Al_Pennywo.. 2
sksandz 1

Monthly Leaders
vulpes 6800
MadHatter 2260
jal 867
Jeff1203 857
muster 791

Top Members
mosessaur 18457
Rincewind 7074
stanleytan 6995
vulpes 6800
Gsuttie 6046

Great Offers
.net hosting
Go To My Pc
Remote Pc Control
zonealarm
spam blocker
web hosting directory
ad server   C#
snadtech GoToMyPc

Top of Page

Advertise | About | Link To Us | Privacy Notice Copyright © 2003 - 2005 CSharpFriends.com  All Rights Reserved  Visual C# Developer Center