Non-visual Coordinate Grid c# -
i want create nonvisual coordinate grid in c# console application such can create grid set size "axb" (for example 9x9 or 6x9 etc.). then, assign number each coordinate (x,y) , access later using specific coordinates. every example of grid have seen in c# works explicitly either make visual grid wpf or somehow using characters in console application. want grid saved data numbers saved each (x,y) coordinate. possible implement using arrays/lists? or suggestions appreciated. actually, have idea of code setting coordinates:
int x = 0; int y = 0; int[,] grid = new int[,] { { x }, { y } };
class grid { public grid(int width, int length) { coordinates = new list<coordinate>(); (int = 1; < width + 1; i++) { (int k = 1; k < length + 1; k++) { coordinates.add(new coordinate(k,i)); } } } list<coordinate> coordinates; int width { get; set; } int length { get; set; } public int accesscoordinate(int x,int y) { return coordinates.where(coord => coord.x == x && coord.y == y) .firstordefault().storedvalue; } public void assignvalue(int x, int y,int value) { coordinates.where(coord => coord.x == x && coord.y == y) .firstordefault().storedvalue = value; } } class coordinate { public coordinate(int _x, int _y) { x = _x; y = _y; } public int x { get; set; } public int y { get; set; } public int storedvalue { get; set; } } and here simple example of how use in console application in case
grid newgrid = new grid(5, 6); newgrid.assignvalue(2, 3, 500); var retrievedvalue = newgrid.accesscoordinate(2, 3); console.writeline(retrievedvalue); console.readline(); and note, might not efficient/best way of doing it, should simplify extent easy modify , understand quickly
Comments
Post a Comment