小典故:为什么数组的索引总是从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/archive/2012/02/23/2364226.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值