C# 我得到了错误索引,这是一个异常

C# 我得到了错误索引,这是一个异常,c#,C#,我是新来的,请帮帮我。代码正在运行,但之后Compiler不打印任何内容,并给出IndexOutOfRangeException错误 class Program { static void Main(string[] args) { string brd = board(); string[] sub = subjects(); Console.WriteLine(brd);

我是新来的,请帮帮我。代码正在运行,但之后Compiler不打印任何内容,并给出IndexOutOfRangeException错误

class Program
    {
        static void Main(string[] args)
        {
            string brd = board();
            string[] sub = subjects();
            Console.WriteLine(brd);
            Console.WriteLine(sub);
            Console.ReadLine();
        }
        public static string board()
        {
            Console.WriteLine("Please Enter Board Name ");
            string Board = Console.ReadLine();
            return Board;
        }
        public static string[] subjects()
        {
            Console.WriteLine("Please Enter How many Subject Do you Want to input");
            int limit = System.Convert.ToInt32(Console.ReadLine());
            string[] Subjects = new string[limit];
            string[] index = new string[limit];
            for (limit = 1; limit <= index.Length; limit++)
            {
                Console.WriteLine("Please Enter Subject Name " + limit );
                Subjects[limit] = Console.ReadLine();
            }
            return Subjects;
        }
           }
类程序
{
静态void Main(字符串[]参数)
{
字符串brd=board();
字符串[]sub=subjects();
控制台写入线(brd);
控制台写入线(sub);
Console.ReadLine();
}
公共静态字符串板()
{
Console.WriteLine(“请输入董事会名称”);
string Board=Console.ReadLine();
返回板;
}
公共静态字符串[]主题()
{
Console.WriteLine(“请输入要输入多少主题”);
int limit=System.Convert.ToInt32(Console.ReadLine());
字符串[]主题=新字符串[限制];
字符串[]索引=新字符串[限制];
对于(限值=1;限值更改为:

for (limit = 1; limit <= index.Length; limit++)
更改此项:

for (limit = 1; limit <= index.Length; limit++)

数组的索引为0,因此要访问的第一个项将位于0

因此,for循环应该从0开始

e、 代码中的for循环应该如下所示

for (limit = 0; limit < index.Length; limit++)
for(limit=0;limit
数组的索引为0,因此第一个要访问的项将位于0

因此,for循环应该从0开始

e、 代码中的for循环应该如下所示

for (limit = 0; limit < index.Length; limit++)
for(limit=0;limit
索引0处的网络起始中的数组。如果您阅读了任何有关网络的教程,您可以在任何地方找到此信息
for(limit=1;索引0处的网络起始中的限制数组)。如果您阅读了任何有关网络的教程,您可以在任何地方找到此信息
for(limit=1;limit可能您希望从0开始,而不是从1开始。@wkl,谢谢,编辑可能您希望从0开始,而不是从1开始。@wkl,谢谢,编辑