Sep 20, 2011

Array of float in C#

using System;

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

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

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

using System;

namespace arrayDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            float[] arr = {2.0f,2.5F,3.0f};

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

2 2.5 3

1 comment:

  1. Anonymous11/05/2013

    thanks, simple but very useful

    ReplyDelete