Click here to Skip to main content
15,887,340 members
Home / Discussions / C#
   

C#

 
GeneralRe: Keeping count of total Pin
MumbleB7-May-08 1:56
MumbleB7-May-08 1:56 
GeneralRe: Keeping count of total Pin
Christian Graus7-May-08 11:56
protectorChristian Graus7-May-08 11:56 
QuestionDisplaying a form from en existing form Pin
Berlus5-May-08 21:35
Berlus5-May-08 21:35 
AnswerRe: Displaying a form from en existing form Pin
Abhijit Jana5-May-08 21:55
professionalAbhijit Jana5-May-08 21:55 
AnswerRe: Displaying a form from en existing form Pin
Christian Graus5-May-08 22:00
protectorChristian Graus5-May-08 22:00 
QuestionCheckBox in ListView Pin
stancrm5-May-08 21:28
stancrm5-May-08 21:28 
AnswerRe: CheckBox in ListView Pin
Christian Graus5-May-08 22:09
protectorChristian Graus5-May-08 22:09 
QuestionIndexers Pin
Steve Declerck5-May-08 20:44
Steve Declerck5-May-08 20:44 
Hi all,

I don't understand most of this "Indexer" code :

namespace UsingIndexers
{
class TestIndexers
{
private string[] MyStrings;

public TestIndexers()
{
MyStrings = new string[] { "This", "is", "an", "indexer", "test" };
}

// array like access
public string this[int index]
{
get
{
if (index < 0 || index >= MyStrings.Length)
{
throw new ArgumentOutOfRangeException();
}
return MyStrings[index];
}
set
{
if (index >= MyStrings.Length)
{
throw new ArgumentOutOfRangeException();
}
else
MyStrings[index] = value;
}
}

static void Main()
{
TestIndexers MyIndexer = new TestIndexers();

Console.WriteLine("index 1 is: {0}", MyIndexer[1]);
}
}
}


Especially I don't understand the use of indexers. Every individual element of MyStrings can be accessed through MyStrings[i]. WHy still additional code for indexing ?
And also this line of code is difficult for me :

public string this[int index]

What is the meaning of "this" ?

Any help is very much appreciated...
Many thanks in advance !!

Best regards, Steve
AnswerRe: Indexers Pin
Vikram A Punathambekar5-May-08 20:59
Vikram A Punathambekar5-May-08 20:59 
GeneralRe: Indexers Pin
Steve Declerck5-May-08 23:15
Steve Declerck5-May-08 23:15 
AnswerRe: Indexers Pin
PIEBALDconsult6-May-08 6:05
mvePIEBALDconsult6-May-08 6:05 
QuestionWorkFlow Project In Visual Studio 2005 Pin
Thaer Hamael5-May-08 19:29
Thaer Hamael5-May-08 19:29 
AnswerRe: WorkFlow Project In Visual Studio 2005 Pin
John_Adams5-May-08 20:57
John_Adams5-May-08 20:57 
GeneralRe: WorkFlow Project In Visual Studio 2005 Pin
Thaer Hamael6-May-08 1:20
Thaer Hamael6-May-08 1:20 
AnswerRe: WorkFlow Project In Visual Studio 2005 Pin
Abhijit Jana5-May-08 22:06
professionalAbhijit Jana5-May-08 22:06 
AnswerRe: WorkFlow Project In Visual Studio 2005 Pin
Abhijit Jana5-May-08 22:31
professionalAbhijit Jana5-May-08 22:31 
GeneralRe: WorkFlow Project In Visual Studio 2005 Pin
Thaer Hamael6-May-08 1:19
Thaer Hamael6-May-08 1:19 
QuestionPicturebox question Pin
MarkB7775-May-08 19:29
MarkB7775-May-08 19:29 
AnswerRe: Picturebox question Pin
Christian Graus5-May-08 20:07
protectorChristian Graus5-May-08 20:07 
AnswerRe: Picturebox question Pin
Yevgen Lisovenko5-May-08 20:16
Yevgen Lisovenko5-May-08 20:16 
GeneralRe: Picturebox question Pin
Christian Graus5-May-08 22:00
protectorChristian Graus5-May-08 22:00 
GeneralRe: Picturebox question Pin
MarkB7776-May-08 15:05
MarkB7776-May-08 15:05 
QuestionPrompt user for Input Pin
Thomas Toh5-May-08 19:04
Thomas Toh5-May-08 19:04 
AnswerRe: Prompt user for Input Pin
Christian Graus5-May-08 19:09
protectorChristian Graus5-May-08 19:09 
GeneralRe: Prompt user for Input Pin
Thomas Toh5-May-08 19:15
Thomas Toh5-May-08 19:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.