Hi friends,
I want to know that How can we count the number of elements in an array?
Thanks
Count the number of elements in an array
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Dec 26, 2011, 7:04 AM EST
int[] arr = new int[5];
int len = arr.Length; // 5
Satyapriya NayakRank #47 · 31.5K reputationPosted Dec 26, 2011, 7:56 AM EST
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
int[] a1 = new int[10];
int len = a1.GetLength(0);
MessageBox.Show(len.ToString());
}
}
}
Thanks