小典故:为什么数组的索引总是从0开始,而不是1?

今天在看Programming C#4.0突然发现了一个典故,挺有意思,发上来分享一下:

C-family languages tend to number things from zero, and C# follows suit. This may seem a little idiosyncratic, but it makes sense to the computer. You can think of it as saying how far into the array you want to look. If you want to look at the thing right at the start of the array, you don’t need to go any distance at all, so an offset of zero gets you the first item.  If  you’re  British,  you’ll  recognize  this  logic  from  floor numbering the first floor in a building in Great Britain is not the one at street level; you have to go up one flight of stairs to get to the first floor.

大概意思是:在英国,如果你想进一楼的话,必须先走进一个地下通道,然后在上一层楼才能到一楼,所以就出来个0层楼,长久以往,0层就被当成第一层使用了。

原文地址:https://www.cnblogs.com/humaoxiao/p/2364226.html