我怎样才能创建一个ArrayList为1(而不是0)的起始指数 [英] How can I create an ArrayList with a starting index of 1 (instead of 0)

查看:277
本文介绍了我怎样才能创建一个ArrayList为1(而不是0)的起始指数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何开始在该指数的ArrayList 1,而不是0?有没有办法做到这一点直接在code?

How can I start the index in an ArrayList at 1 instead of 0? Is there a way to do that directly in code?

(请注意,我要求的ArrayList ,对于普通阵列请参阅<一个href=\"http://stackoverflow.com/questions/82943/initializing-an-array-on-arbitrary-starting-index-in-c-sharp\">Initializing在C#上任意起始点指数数组)

(Note that I am asking for ArrayList, for plain arrays please see Initializing an array on arbitrary starting index in c#)

推荐答案

最明显的方式做这将是包裹在自己实现一个ArrayList,并在使用该索引的所有操作的索引减1。

The obvious way to do it would be to wrap an ArrayList in your own implementation, and subtract 1 from the indexer in all operations that uses the index.

您可以在事实上也宣布在.NET中的数组,有一个任意下界(向下滚动到章节创建阵列非零下限)。

You can in fact also declare an array in .NET, that has an arbitrary lower bound (Scroll down to the section "Creating Arrays with a Non-zero Lower Bound").

随着中说,请不要做生产code。它的事项是一致的。

With that said, please don't do it in production code. It matters to be consistent.

这篇关于我怎样才能创建一个ArrayList为1(而不是0)的起始指数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆