Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace TableNet
- {
- public class Table
- {
- private readonly Cell[,] _cells;
- public Cell this[int i, int j]
- {
- get => _cells[i, j];
- set
- {
- if(value != null)
- _cells[i, j] = value;
- else throw new ArgumentNullException();
- }
- }
- public ReadOnlyCollection<Row> Rows { get; }
- public ReadOnlyCollection<Column> Columns { get; }
- public Table(int rows, int columns)
- {
- _cells = new Cell[rows, columns];
- for (var i = 0; i < rows; i++)
- {
- for (var j = 0; j < columns; j++)
- {
- _cells[i, j] = new Cell();
- }
- }
- Rows = CreateRows(rows, columns, Row.DEFAULT_ROW_HEIGHT);
- Columns = CreateColumns(rows, columns, Column.DEFAULT_COLUMN_WIDTH);
- }
- public ReadOnlyCollection<Row> CreateRows(int rows, int columns, int height)
- {
- Row[] r = new Row[rows];
- for (var i = 0; i < rows; i++)
- {
- r[i] = new Row(this, i, columns, height);
- }
- return Array.AsReadOnly(r);
- }
- private ReadOnlyCollection<Column> CreateColumns(int rows, int columns, int width)
- {
- Column[] r = new Column[columns];
- for (var i = 0; i < columns; i++)
- {
- r[i] = new Column(this, i, rows, width);
- }
- return Array.AsReadOnly(r);
- }
- }
- }
- namespace TableNet
- {
- public class Row
- {
- public const int DEFAULT_ROW_HEIGHT = 3;
- public int Height
- {
- get => Height;
- set => Height = Math.Max(0, value);
- }
- public int Columns { get; }
- private readonly Table _table;
- private readonly int _rowIndex;
- //public char Filler { set => Cells.ForEach(c => c.Filler = value); }
- internal Row(Table table, int rowIndex, int columns, int height)
- {
- _table = table;
- _rowIndex = rowIndex;
- Columns = columns;
- Height = height;
- }
- public Cell this[int column]
- {
- get => _table[_rowIndex, column];
- set => _table[_rowIndex, column] = value;
- }
- }
- }
Add Comment
Please, Sign In to add comment