Last active
December 20, 2022 13:37
-
-
Save PasterLak/1d5c26d18f52c69f52051ee8612e13a9 to your computer and use it in GitHub Desktop.
Array3D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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