Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What does Array.Length property of array class do in C#?
The Array.Lenth property in C# is used to find the length of the array.
Let’s set the array class first −
Array arr = Array.CreateInstance(typeof(String), 3);
arr.SetValue("Electronics", 0);
arr.SetValue("Clothing", 1);
arr.SetValue("Appliances", 2);
Now since the array’s length is 3, the Length property will give the result 3 −
arr.Length
The following is the code to implement Array.Length property of array class −
Example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace lower {
class Program {
static void Main(string[] args) {
Array arr = Array.CreateInstance(typeof(String), 3);
arr.SetValue("Electronics", 0);
arr.SetValue("Clothing", 1);
arr.SetValue("Appliances", 2);
Console.WriteLine("Length: {0}",arr.Length.ToString());
Console.ReadLine();
}
}
}
Output
Length: 3
Advertisements