How can I start the index in an ArrayList at 1 instead of 0? Is there a way to do that directly in code?
(Note that I am asking for ArrayList, for plain arrays please see Initializing an array on arbitrary starting index in c#)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.
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”).
With that said, please don’t do it in production code. It matters to be consistent.