How to bring each word letter in array c#

I have a problem in my code and I have no idea how to fix it. I need to copy every letter of the user entered word to array, but there is an error "Index was outside the bounds of the array". I know that thir error means that I don't have correct size of the array, but I am using ReadLine and I can't enter static size. It can be changed due user entered text.

Code:

static void Main(string[] args)
        {

            int c = 0;
            string text = Console.ReadLine();

            string[] str = new string[] { };



            foreach (char letter in text)
            {

                str[c] = Convert.ToString(letter);
                Console.WriteLine(str[c]);
                c++;
            }
        }


Error screenshot:

enter image description here



Read more here: https://stackoverflow.com/questions/64942272/how-to-bring-each-word-letter-in-array-c-sharp

Content Attribution

This content was originally published by George at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: