Dynamic Array in C#

In this article I will explain that how to create dynamic in array.
  • 4311

We can declaration Dynamic array I've initialized them as just standard variables within my Start function, so I just get a Null ReferenceException: Object Reference not set to an instance of an object.

namespace demo_array

{

    class Program

    {

       

        static void Main(string[] args)

        {

            string[] statiarray = new string[12] { "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec" };

            Console.WriteLine(statiarray[0]);

            Console.WriteLine(statiarray[1]);

            Console.WriteLine(statiarray[2]);

            Console.WriteLine(statiarray[3]);

            Console.WriteLine(statiarray[4]);

            Console.WriteLine(statiarray[5]);

            Console.WriteLine(statiarray[6]);

            Console.WriteLine(statiarray[7]);

            Console.WriteLine(statiarray[8]);

            Console.WriteLine(statiarray[9]);

            Console.WriteLine(statiarray[10]);

            Console.WriteLine(statiarray[11]);

            Console.ReadKey();

 

            //Get 2nd method output

            //  foreach (string strval in statiarray)

            {

                //  Console.WriteLine(strval);   

                //  Console.ReadKey();

            }      

        }

    }

}

Output

staticarray.jpg

Ask Your Question 

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

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.