Sep 20, 2011

Array of decimal in C#

using System;

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

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


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

using System;

namespace arrayDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            decimal[] arr = {2.0m,2.5M,3.0M};

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

2.0 2.5 3.0

1 comment:

  1. Hiya! Does the frequency of updates of your portal depend on something or you compose blog articles when you have an inspiration or spare time for that? Waiting forward to hear from you.

    ReplyDelete