473,386 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Why array start with 0 index in C#.net ?

I want to know ,Why array index start with 0,why not with 1?
Feb 15 '11 #1
1 4548
GaryTexmo
1,501 Expert 1GB
The original concept of an array was pointer to an address in memory of the index of the first element of the array. Thus the index acts as an offset. This originated in C (the language the C# syntax is taken from) and probably even before.

So... in memory, lets say your array exists at 0xFFFF0000 (just a made up address) and contains { 4, 8, 7 }

You'd have the following...

0xFFFF0000 = 4
0xFFFF0004 = 8
0xFFFF0008 = 7

(the address goes up by four bytes because it's a 32-bit integer)

So when you access your array, index 0 means zero offset. Index 1 means 1 32-bit integer offset, thus 4 bytes. And so on.

I believe languages that use 1-indexed arrays are still doing this, they just shift the offset because some people feel it's more natural to think of 1 as the 1st item, not zero.

Note, this is the same with images... they all start at zero, not one. Something to be aware of :)

Hope that helps!

*edit: Sorry, the above examples are with an array of 32-bit integers. Generally the offset is calculated as: index * size_of_single_element. Which isn't terribly important... but that's why arrays are zero-indexed :D
Feb 15 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: tim | last post by:
I have an array. I have the name of an element. I need the related index. Is there a sort of "GetIndex" method or I have to use the For Next cicle until I met the given name?
6
by: Yanhao Zhu | last post by:
Hi, all, If I have an array like int m = new int { 0, 1, 2, 3 }, is there a way I can separate the array into two, like int m01 = somefunction?(m,0,2) // m01 will hold 1st and 2nd items in...
1
by: hbomb | last post by:
Does anyone know what the Control Array's indecies are?
4
by: christiang | last post by:
Hi guys I'd like to sort a multidimensional array that hasn't numerical index, in fact it is like: Array ( => Array ( => mobile => 1 )
9
by: AtariPete | last post by:
Hi all, My scenario is as follows: * Receive a base 1 array (index starts at 1 instead of 0) of data from a COM component . * Need to pass this array to a .net component that requires its...
2
by: poojapo | last post by:
hi guys, how do i search for a pattern(which is a regular expression) inside an array element and get the position of the occurence of it? @array is the array.I am at element $array.$n here is...
0
by: RickPowell | last post by:
I am writing a WinForm application in C#, .NET Framework 2.0, Visual Studio 2005. It must be Section 508 compliant; i.e. ACCESSIBILITY features on. My main tester, a blind person, would like his...
1
by: Gilles Ganault | last post by:
Hello Out of curiosity, is there a better way in Python to iterate through an array, and return the index of each item that contains the bit somewhere in its value, ie. index() doesn't work...
2
JnrJnr
by: JnrJnr | last post by:
I'm going to leave out most details so say for instance i have a combobox and when I select a car from the combobox I have a variable called Index that grows with each selection of the combobox. that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.