using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace indexer
{
class IndexerClass
{
private int[] myArray = new int[100];
public int this[int index]
{
get
{
if (index < 0 || index > 100)
return 0;
else
return myArray[index];
}
set
{
if (index >= 0 && index <= 100)
myArray[index] = value;
}
}
}
class MainClass
{
static void Main(string[] args)
{
IndexerClass b = new IndexerClass();
b[5] = 256;
b[8] = 1024;
for (int i = 0; i <= 10; i++)
{
Console.WriteLine("Element #{0}={1}.", i, b[i]);
}
Console.ReadLine();
}
}
}

被折叠的 条评论
为什么被折叠?



