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

CsharpProgrammingServer Side Programming

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("\nSize of Array: "+arr.Length);
      }
   }
}

Output

Array...
6 3 8 4
Size of Array: 4
raja
Published on 31-Aug-2018 12:44:36
Advertisements