arrays - Using a 'foreach' loop with stringArray in C# - Stack Overflow

PHOTO EMBED

Thu Apr 27 2023 03:52:10 GMT+0000 (Coordinated Universal Time)

Saved by @javicinhio #cs

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] stringArray = {"hey", "Tom"};

            for (int i = 0; i < stringArray.Length; i++ )
            {
                stringArray[i] += "  dad";
                Console.WriteLine(stringArray[i]);
            }

            Array.Resize(ref stringArray, stringArray.Length + 1);

            // Add bob to the last element of the array
            stringArray[stringArray.Length - 1] =" bob";

            foreach (string s in stringArray)
            {
                string b = s + "sad";
                Console.WriteLine(s);
                //Console.WriteLine(stringArray);
            }
        }
    }
}
content_copyCOPY

https://stackoverflow.com/questions/16512161/using-a-foreach-loop-with-stringarray-in-c-sharp