我写了一个类,该类允许用户设置数组的下限,例如“ myArray(-5,10)”,其中-5开始索引,数组的长度为10。但是当我比较我<= myArray.GetArrayLength时出现错误。我做错了。我会寻求任何帮助。
using System;
namespace UsArrClass
{
class Program
{
class UserArr
{
private int[] _UsArr;
private int _start;
private int _len;
public int[] UsArr
{
get => this._UsArr;
set => this._UsArr = value;
}
public int BotomBoundary
{
get => this._start;
set => this._start = value;
}
public int TopBoundary => (GetUserArrLength -1) + BotomBoundary;
public int GetUserArrLength => _len;
public UserArr(int start, int len)
{
this.BotomBoundary = start;
this._len = len;
UsArr = new int [len];
}
public int this[int n]
{
get => UsArr[n - BotomBoundary];
set => UsArr[n - BotomBoundary] = value;
}
static void Main(string[] args)
{
UserArr myarr = new UserArr( 0, 3);
for (int i = myarr.BotomBoundary; i <= myarr.GetUserArrLength; i++)
{
myarr[i] = i;
Console.Write(" "+ myarr[i]);
}
Console.WriteLine();
Console.WriteLine(myarr.TopBoundary);
Console.WriteLine(myarr[1]);
Console.WriteLine(myarr.BotomBoundary);
Console.WriteLine(myarr.GetUserArrLength);
}
}
}
}