Q:

appending to a string array in C#

    string Input = "";
    string[] Words = { "elephant", "lion" };
    string[] Clues = { "Has trunk?", "Is gray?", "Is yellow?", "Has mane?"};

.........
        Console.WriteLine("Do you want to add you own animal? y/n ? \n");
        Input = Console.ReadLine();
        if (Input == "Y" || Input == "y")
        {
            Console.WriteLine("Enter an animal name: \n");
            //Array.Resize(ref Words, Words.Length + 1);
            Input = Console.ReadLine();
            Words[Words.Length] = Input;

            Console.WriteLine("Enter 2 clues \n");
            for (int i = 1; i <=2 ; i++)
            {
                Console.WriteLine("Clue" + i + ":");
                Clues[Clues.Length] = Console.ReadLine();

            }

        }

This is the standard guess the animal game..
I am getting an index out of bounds at line Words[Words.Length] = Input;.. the new animal  and clues entered also needs to be available the next time i play the game..

A:

You can use List<string> instead of Array. Your code throw exception because you are trying to add element to an Array in outranged index. I modified your code like this;
        string Input = "";
        var Words = new List<string> { "elephant", "lion" };
        var Clues = new List<string> { "Has trunk?", "Is gray?", "Is yellow?", "Has mane?" };
        Console.WriteLine("Do you want to add you own animal? y/n ? \n");
        Input = Console.ReadLine();
        if (Input == "Y" || Input == "y")
        {
            Console.WriteLine("Enter an animal name: \n");
            //Array.Resize(ref Words, Words.Length + 1);
            Input = Console.ReadLine();
            Words.Add(Input);

            Console.WriteLine("Enter 2 clues \n");
            for (int i = 1; i <= 2; i++)
            {
                Console.WriteLine("Clue" + i + ":");
                var clueInput = Console.ReadLine();
                Clues.Add(clueInput);

            }

        }

