- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Are arrays zero indexed in C#?
Yes, arrays zero indexed in C#. Let us see how −
- If the array is empty, it has zero elements and has length 0.
- If the array has one element in 0 indexes, then it has length 1.
- If the array has two elements in 0 and 1 indexes, then it has length 2.
- If the array has three elements in 0, 1 and 2 indexes, then it has length 3.
The following states that an array in C# begins with index 0 −
/* begin from index 0 */ for ( i = 0; i < 5; i++ ) { n[ i ] = i + 5; }
Example
You can try to run the following to see how array indexing implements in C# −
using System; namespace ArrayApplication { class MyArray { static void Main(string[] args) { int [] n = new int[5]; int i,j; /* begings from index 0 */ for ( i = 0; i < 5; i++ ) { n[ i ] = i + 5; } for (j = 0; j < 5; j++ ) { Console.WriteLine("Element[{0}] = {1}", j, n[j]); } Console.ReadKey(); } } }
Output
Element[0] = 5 Element[1] = 6 Element[2] = 7 Element[3] = 8 Element[4] = 9
- Related Articles
- Why does the indexing start with zero in C# arrays?
- Binary Indexed Tree or Fenwick Tree in C++?
- What are dynamic arrays in C#?
- What are mixed arrays in C#?
- What are jagged arrays in C#?
- Indexed collections in JavaScript
- What are parameter/param arrays in C#?
- What are two-dimensional arrays in C#?
- How arrays are passed to functions in C/C++
- What are hashed files and indexed file organization(DBMS)?
- PHP Indexed Array
- Binary Indexed Tree: Range Update and Range Queries in C++
- Maximum Sum Increasing Subsequence using Binary Indexed Tree in C++
- How are values assigned to arrays in C#?
- Zero Initialization in C++

Advertisements