Hi friends,
I want to know that How can we count the number of elements in an array?
Thanks
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Dec 26, 2011, 12:56 PM
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
VulpesPosted Dec 26, 2011, 12:04 PM
int[] arr = new int[5];
int len = arr.Length; // 5