English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

3 answers

An indexer is simply an indexed property. A common example would be an array - by calling array[3] you are accessing it via an indexer. The index can be anything, though - not just an integer. For example, if you want to create an object that looks up a specific item by name, you could write:

public class DoodadCollection
{
private Doodad[] myDoodads;

public Doodad this[string name]
{
get
{
Doodad myDoodad = null;
for(int i=0; i {
if(myDoodads[i].Name == name)
{
myDoodad = myDoodads[i];
break;
}
}
return myDoodad;
}
}
}

2007-03-21 22:54:26 · answer #1 · answered by Rex M 6 · 0 1

What Is Indexer

2016-12-11 14:41:42 · answer #2 · answered by Anonymous · 0 0

"Arrays are accessed by using the index.In the same way in C# also, Indexer is used to access the class instances by means of index notation."
check this site with the example:
http://www.codeproject.com/useritems/Indexer_in_C__Programmin.asp

2007-03-21 22:50:24 · answer #3 · answered by abd 5 · 0 1

fedest.com, questions and answers