Creating a non 0 based array
I need to create an Array where the first element is not 0. I know it can be done but I can't find anything that tells me how.
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Jan MontanoRank #1,295 · 1.3K reputationPosted Dec 22, 2008, 6:24 PM EST
The only way I know of creating a non zero base index array is by using Array.CreateInstance
// create a 1 dimensional array of type int with 5 elements with a starting index of 1.
Array myArray = Array.CreateInstance(typeof(int), new int[1] { 5 }, new int[1] { 1 });
// store 10 to the array with index 1.
myArray.SetValue(10, 1);
// store 9 to the array with index 0. this will produce an error because our staring index is 1.
myArray.SetValue(9,0);
Gordon8 reputationPosted Dec 23, 2008, 1:24 AM EST