There is no built-in dynamic equivalent of two-dimensional arrays that I know of, but you can easily get more or less the same functional.
Define the Coordinate class with this API:
public class Coordinate : IEquatable<Coordinate> { public Coordinate(int x, int y); public int X { get; } public int Y { get; }
Now you can create a collection of these Coordinate instances.
If you create a HashSet<Coordinate> , you will be guaranteed that you cannot add coordinates if it is already added because it overrides Equals.
If you want, you can expand the coordinate to Coordinate<T> as follows:
public class Coordinate<T> //... {
This will allow you to associate a strongly typed element with each coordinate, for example:
var items = new HashSet<Coordinate<string>>(); items.Add(new Coordinate<string>(1, 4) { Item = "Foo" }); items.Add(new Coordinate<string>(7, 19) { Item = "Foo" });
source share