dans le bloc de code suivant indexeur, pourquoi avons-nous besoin:question sur un simple indexeur (C#)
public string this[int pos]
{
get
{
return myData[pos];
}
set
{
myData[pos] = value;
}
}
ce qui fait exactement "ce" dans ce [int pos] faire? Merci
/// Indexer Code Block starts here
using System;
/// <summary>
/// A simple indexer example.
/// </summary>
class IntIndexer
{
private string[] myData;
public IntIndexer(int size)
{
myData = new string[size];
for (int i = 0; i < size; i++)
{
myData[i] = "empty";
}
}
public string this[int pos]
{
get
{
return myData[pos];
}
set
{
myData[pos] = value;
}
}
static void Main(string[] args)
{
int size = 10;
IntIndexer myInd = new IntIndexer(size);
myInd[9] = "Some Value";
myInd[3] = "Another Value";
myInd[5] = "Any Value";
Console.WriteLine("\nIndexer Output\n");
for (int i = 0; i < size; i++)
{
Console.WriteLine("myInd[{0}]: {1}", i, myInd[i]);
}
}
}
Quelqu'un d'autre a-t-il une odeur de devoirs? Si c'est ... il devrait être étiqueté comme tel. –
ce n'est pas les devoirs. Im enseigner moi-même C# à travers un tutoriel en ligne http://www.csharp-station.com/Tutorials/Lesson11.aspx – user133466