Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 具有任意索引边界的数组中的数组索引超出边界_C#_Arrays - Fatal编程技术网

C# 具有任意索引边界的数组中的数组索引超出边界

C# 具有任意索引边界的数组中的数组索引超出边界,c#,arrays,C#,Arrays,我编写了一个类,允许用户在实例“myArray(-5,10)”中设置数组的下界,其中-5开始索引和10数组长度。但是当我比较这个时,我得到了一个错误; set=>这个值; } 公共边界 { get=>这个; 设置=>此值。_start=值; } public int-TopBoundary=>(GetUserArrLength-1)+BotomBoundary; public int GetUserArrLength=>\u len; 公共用户arr(int start,int len) { t

我编写了一个类,允许用户在实例“myArray(-5,10)”中设置数组的下界,其中-5开始索引和10数组长度。但是当我比较这个时,我得到了一个错误; set=>这个值; } 公共边界 { get=>这个; 设置=>此值。_start=值; } public int-TopBoundary=>(GetUserArrLength-1)+BotomBoundary; public int GetUserArrLength=>\u len; 公共用户arr(int start,int len) { this.BotomBoundary=开始; 这个。_len=len; UsArr=新整数[len]; } 公共int这个[int n] { get=>UsArr[n-BotomBoundary]; set=>UsArr[n-BotomBoundary]=值; } 静态void Main(字符串[]参数) { UserArr myarr=新的UserArr(0,3);
对于(int i=myarr.BotomBoundary;i它应该是
i
我知道如果是这样的话它会工作,但是普通数组我可以与它的自身长度进行比较。数组索引从0到长度-1。你可以与长度进行比较,但是
arr[arr.Length]中没有任何内容。
谢谢朋友们,我可能弄错了;)tiredIt应该是
i
我知道如果是这样的话它会工作,但是我可以将普通数组与它的自身长度进行比较。数组索引从0到长度-1。你可以与长度进行比较,但是
arr[arr.Length]
中没有任何内容,谢谢朋友们,我可能弄错了;)累了
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);


            }
        }
    }
}