Length an Array in C#

In this article I will explain that how to Length in Array.
  • 4502

This C# example program uses the Length property on an array. Length returns the array size. Identifying the length of an array is of great practical importance in real life. Advance usage of arrays is outside the scope of this tutorial as the topics of our tutorial are already covered, I will leave you with two example of how to use the array.

namespace demo_array

{

    class Program

    {     

        static void Main(string[] args)

        {

            int[] nums = new int[10];

            Console.WriteLine("Length of nums is " + nums.Length);

            for (int i = 0; i < nums.Length; i++)

                nums[i] = i * i;

            Console.Write("Here is nums: ");

            for (int i = 0; i < nums.Length; i++)

                Console.Write(nums[i] + " ");

            Console.ReadKey();         

        }

    }

}

Output

lenght_array.jpg

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.