Skip to content

Instantly share code, notes, and snippets.

@PasterLak
Last active December 20, 2022 13:37
Show Gist options
  • Save PasterLak/1d5c26d18f52c69f52051ee8612e13a9 to your computer and use it in GitHub Desktop.
Save PasterLak/1d5c26d18f52c69f52051ee8612e13a9 to your computer and use it in GitHub Desktop.
Array3D
public class Array3D<T>
{
private T[] _data;
private int _width;
private int _height;
private int _depth;
public int Width => _width;
public int Height => _height;
public int Depth => _depth;
public Array3D(int width, int height, int depth)
{
_data = new T[width * height * depth];
_width = width;
_height = height;
_depth = depth;
}
public T this[int width, int height, int depth]
{
get => _data[GetIndex(width, height, depth)];
set => _data[GetIndex(width, height, depth)] = value;
}
private int GetIndex(int x, int y, int z) => x + _width * (y + _depth * z);
public override string ToString()
{
return _data.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment