How do I determine the size of my array in C#


Firstly, set an array −

int[] arr = {6, 3, 8, 4};

Now, use the Length property to get the size of the array −

arr.Length

Let us see the complete code −

Example

 Live Demo

using System;
namespace Demo {
   public class Demo {
      public static void Main(string[] args) {
         int[] arr = {6, 3, 8, 4};
         Console.WriteLine("Array...");
         foreach (int i in arr) {
            Console.Write(i + " ");
         }
         Console.WriteLine("
Size of Array: "+arr.Length);       }    } }

Output

Array...
6 3 8 4
Size of Array: 4

Updated on: 22-Jun-2020

117 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements