How could I store negative coordinates with negative indexes with C#?


I’m looking for somekind of 2 dimensional “table” solution (with C#) which’s size could start from negative indexes. For example From -3,-3 to 3,3. And this table should be able to store one value, most likely a string and I’d like to easily access offset values with iterators. Dynamic size would be a plus but not must.

I have this randomly generated world consisting of blocks, similar to Minecraft/Cubeworld/Trove etc, and I’d like to save my chunks with zero point of 0,0.

Currently my game stores the chunks in a normal 2 dimensional array, for example size of 100, so the zero point of the game would be 49,49 but this causes a bit too much hassle with all the other code.

So are there any kind of storing solutions supporting negative indexes?

If you use a data structure like a Dictionary (in System.Collections.Generic), you can index chunks by their two dimensional coordinates (or rather, the hash of that value).

To my knowledge, this is the solution that Minecraft uses for indexing their chunks.