using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _0300_索引器声明和使用
{
class Z
{
private long[] arr = new long[100];//私有
private long[] arr1 = new long[300];//私有
public long this[int index]//对数组进行限制性访问,索引,等同属性
//对树状进行限制性访问,索引,等同属性
{
get
{
if (index < 0 || index >= 100)
{
return 0;
}
else
{
return arr[index];
}
}
set
{
if (!(index < 0 || index >= 100))
{
arr[index] = value;
}
}
}
public long OutPut()
{
return arr[2];
}
static void Main()
{
Z z = new Z();
z.arr[2] = 121;
z[2] = 234;
Z z1 = new Z();
z1[0] = 123;
// z[6] = 546;
Console.WriteLine(z.OutPut());
Console.ReadLine();
}
}
}