Mama Tate
Mama Tate

Reputation: 283

One array calling another one's methods

I will try to ask the best way i can..

I have ..let's say 5 instances of Chunks in my Map class.The Chunks instances contain array of Point struct data.

Now what i am trying to achieve is to hold this Point data in the Chunks..but i want to have them also sorted in the Map class in one array and access them through static array.

I want to call the Chunk instances methods through another array in the Map class like:

"call:" Map.Points[13,2,1].Destroy() "which is directly calling: " => Chunk[1].Points[13,2,1].Destroy()

"call:" Map.Points[53,24,1].Destroy() "which is directly calling: " => Chunk[1].Points[12,12,1].Destroy()

So i just need straight access through another array.Is there any way to achieve this?

Upvotes: 0

Views: 47

Answers (1)

Erik
Erik

Reputation: 12858

You could use the class indexer property in C#.

This is done by creating a property named this with the return type that you want (Point in this case).

You can have it take in any number and type of arguments in the [...] accessor definition. You seem to want a sets of three integers, so you'd do something like this:

public class Map
{
  public Point this[x, y, i]
  {
    get { return this.Chunks[i].Points[x, y, i]; }
  }
}

Then you could do Map[13,2,1].Destroy(). I'm not 100% sure of your structures/methods but this looks like what you are trying to do.

Upvotes: 1

Related Questions