Indexing Generic Arrays
-
All, I have encoded an object that contains a Generic array at it's heart. One of the uses I have for this is to store double[] arrays at each index point. I have done this rather than using multidimensional arrays as the class containing the generic array has additional functionality I need that multidimensional arrays don't provide. Everything works but complications arise because the double[] arrays that get loaded into the generic array are not full, ie. they need to be updated on the fly. Because of the nested nature of the arrays I want to update I've realised that std indexing won't work. if anyone can offer some guidance on the best approach ere i'd appreciate it. Or, do I have no choice but to unload the array at each index point in order to update it? A brief snippet of my code for guidance: public class CircularQueue; { private T[] QBuffer; // Generic Array public T this[int Index] // Indexing code { get { if ( (Index < 0) || (Index >= QBuffer.Length) ) { } return QBuffer[Index]; } set { T Item = value; Insert(Item, Index); } } // End Index ... } Declaration: protected CircularQueue<double[]> CustomData; Usage: CustomData.Initialize(SizeOfGenericArray); //Initialize CustomData.Enqueue(IndexItem); //Add an item(double[]) CustomData[GenericArrayIndex][ItemIndex] = NewValue; //This fails! So the indexing code I have is useful only for indexing the generic array. Indexing the nested arrays is more of a problem. Any help offered willl be greatly appreciated. Regards, Dave
Regards, Dave
-
All, I have encoded an object that contains a Generic array at it's heart. One of the uses I have for this is to store double[] arrays at each index point. I have done this rather than using multidimensional arrays as the class containing the generic array has additional functionality I need that multidimensional arrays don't provide. Everything works but complications arise because the double[] arrays that get loaded into the generic array are not full, ie. they need to be updated on the fly. Because of the nested nature of the arrays I want to update I've realised that std indexing won't work. if anyone can offer some guidance on the best approach ere i'd appreciate it. Or, do I have no choice but to unload the array at each index point in order to update it? A brief snippet of my code for guidance: public class CircularQueue; { private T[] QBuffer; // Generic Array public T this[int Index] // Indexing code { get { if ( (Index < 0) || (Index >= QBuffer.Length) ) { } return QBuffer[Index]; } set { T Item = value; Insert(Item, Index); } } // End Index ... } Declaration: protected CircularQueue<double[]> CustomData; Usage: CustomData.Initialize(SizeOfGenericArray); //Initialize CustomData.Enqueue(IndexItem); //Add an item(double[]) CustomData[GenericArrayIndex][ItemIndex] = NewValue; //This fails! So the indexing code I have is useful only for indexing the generic array. Indexing the nested arrays is more of a problem. Any help offered willl be greatly appreciated. Regards, Dave
Regards, Dave
I don't see anything wrong with the code. What do you mean when you say that it "fails"? What happens? Do you get a compilation error? A runtime error? In what way does the result differ from what you expected?
Despite everything, the person most likely to be fooling you next is yourself.