Sep 20, 2011

Array of double in C#

Declaring, defining and initializing the array of double at the same time in C#

using System;

namespace arrayDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            double[] arr = new double[3];

            arr[0]= 2.0d;
            arr[1]=2.5D;
            arr[2]=3.0;
          
            //printing value of each element in the array
            foreach (double element in arr)
            {
                Console.Write("{0} ", element);
            }
            Console.ReadKey();
        }
    }
}


using System;

namespace arrayDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            double[] arr = {2.0d,2.5D,3.0};

            //printing value of each element in the array
            foreach (double element in arr)
            {
                Console.Write("{0} ", element);
            }
            Console.ReadKey();
        }
    }
}

2 2.5 3

No comments:

Post a Comment