class Program
{
static void Main(string[] args)
{
IntIndexer myIntIndexer = new IntIndexer(5);
for (int i = 0; i < 5; i++)
{
Console.WriteLine(myIntIndexer[i]);
}
}
}
class IntIndexer
{
private string[] myData;
public IntIndexer(int size)
{
myData = new string[size];
for (int i = 0; i < size; i++)
{
Console.WriteLine("Enter an antry");
myData[i] = Console.ReadLine();
Console.WriteLine("---------------------------------");
}
}
}
コンパイル時にエラーが発生する[]でインデックス付けをIntIndexer型の式に適用できません。このエラーは、Console.WriteLine(myIntIndexer[i]);
コンストラクタで初期化されたクラスオブジェクトからの配列の出力方法
あなたの問題は 'Console.WriteLine(myIntIndexer [i])'です。あなたの変数はコンテナではありません –
'IntIndexer'クラスはインデクサーを持っていません。詳細については、[this](https://msdn.microsoft.com/en-us/library/6x16t2tx.aspx)の記事を参照してください。 –