Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Indexing Generic Arrays

Indexing Generic Arrays

Scheduled Pinned Locked Moved C#
helpdatabasedata-structuresquestionannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DwR
    wrote on last edited by
    #1

    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

    G 1 Reply Last reply
    0
    • D DwR

      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

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups