索引超出数组的范围。(C#)

时间:2018-12-24 09:36:06

标签: c# arrays

我试图在这里做一个简单的对话,但是我陷入了困境。 错误:索引超出数组的范围。(由x4,4th数组引起) 我试图给他们足够的数组大小,但仍然会出错。有人知道吗?

using System;

namespace AiApp
{
    class CleoVers1
    {
        static void Main(string[] args)
        {
            int i,j,n=9999,x=9999;
            string[] x0 = new string[] {};
            string[] x1 = new string[] {"hello","Hello","hi","Hi","hey","Hey"};
            string[] x2 = new string[] { "How are you","How are you?","How is it going","How is it going?", "How are you doing", "How are you doing?"};
            string[] x3 = new string[] { "I am fine","Fine","fine","i am Fine","I am good!","I am good","I Am Good","Good","good"};
            string[] x4 = new string[] {"How old you are","How old are you","What is your age","What is your age"};

            for (i = 0; i < n; i++)
            {
                Console.WriteLine("Enter your statement");
                string input1 = Console.ReadLine();

                for (j= 0; j< x; j++)
                {
                    if (input1.Contains(x1[j]))
                    { 
                        Console.WriteLine("Hi!");
                        break;
                    }

                    if (input1.Contains(x2[j]))
                    { 
                        Console.WriteLine("I am fine!How about you?");
                        break;
                    }

                    if (input1.Contains(x3[j]))
                    { 
                        Console.WriteLine("Good!Ask me something!");
                        break;
                    }

                    if (input1.Contains(x4[j]))
                    {
                        Console.WriteLine("I am 1 day old!Where do you live by the way?");
                        break;
                    }
                }
                n= n+1;
            }
            Console.ReadLine();
        }       
    }
}

0 个答案:

没有答案