- 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
Why does the indexing start with zero in C# arrays?
Arrays were a pointer to an address in memory of the index. This index was the 1st element of the array. Here, the index is like an offset and the concept even before C language originated.
Let’s say your array elements begins from 0Xff000 and has 5 elements like {35,23,67,88,90}. Therefore, you array in memory would be like the following because int is stored using 4 bytes.
0Xff000 has 35 0Xff004 has 23 0Xff008 has 67 0Xff012 has 88 0Xff016 has 90
That would mean when the array is accessed, zero offsets would be index 0.
Let us further see the concept of zero indexing in C# −
- If array is empty, it has zero elements and has length 0.
- If array has one element in 0 index, then it has length 1.
- If array has two elements in 0 and 1 indexes, then it has length 2.
- If 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 < 10; i++ ) { num[ i ] = i + 10; }
- Related Articles
- Why does the JavaScript need to start with “;”?
- Are arrays zero indexed in C#?
- Why C/C++ variables doesn’t start with numbers
- Why do Lua arrays (tables) start at 1 instead of 0?
- Why does Python sometimes take so long to start on Windows?
- Why array index starts from zero in C/C++ ?
- Why is address zero used for the null pointer in C/C++?
- Why C/C++ array index starts from zero?
- Why does tooth decay start when the pH of mouth is lower than 5.5?
- Does C++ support Variable Length Arrays
- Why is the size of an empty class not zero in C++?
- Why does any government start makeover of cities when they have foreign delegates visiting the city?
- Why is a[i] == i[a] in C/C++ arrays?
- Why would a jQuery variable start with a dollar sign?
- Add the element in a Python list with help of indexing

Advertisements