Using String Array in C#

In this article I will explain that how to create Array using String in Array.
  • 5856

We declare an Array "week" capable of seven String values and assigns the seven values as days in a week. And retrieve the elements of the Array using a foreach loop. An interesting point here is that the strings themselves are not stored in the array. Rather, just a reference to the string data is in the array. The strings are typically stored in the managed heap.

namespace demo_array

{

    class Program

    {

       // Create string array of seven references.

        static void Main(string[] args)

        {

           string[] week = new string[7];

            week[0] = "Sunday";

            week[1] = "Monday";

            week[2] = "Tuesday";

            week[3] = "Wednsday";

            week[4] = "Thursday";

            week[5] = "friday";

            week[6] = "Saturday";

 

            foreach (string strweek in week)

            {

                Console.WriteLine(strweek);                

            }

            Console.ReadKey();

        }

    }

}

Output

array_week.jpg

Further Readings
 
You may also want to read these related articles.

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.