Sunday, 25 August 2013

Write a class with some properties and indexed

Write a class with some properties and indexed References Is there a better way to write it? I need the best way to write it. It is this principle? Please show me a better way it breaks SRP? public class PlacementLocation { public int Row { get; set; } public int Column { get; set; } public int Location { get; set; } } public class PlacementLocations : PlacementLocation { private void SetLocationInList() { _placementLocations = new List { new PlacementLocation {Column = 1, Row = 9, Location = 1}, new PlacementLocation {Column = 2, Row = 9, Location = 2}, new PlacementLocation {Column = 3, Row = 9, Location = 3}, new PlacementLocation {Column = 4, Row = 9, Location = 4}, new PlacementLocation {Column = 5, Row = 9, Location = 5}, }; } private List _placementLocations; public PlacementLocations() { _placementLocations = new List(); SetLocationInList(); } public Tuple this[int location] { get { return new Tuple(_placementLocations[location].Row, _placementLocations[location].Column); } } public int this[int row, int column] { get { PlacementLocation singleOrDefault = _placementLocations.SingleOrDefault(d => d.Column == column && d.Row == row); return singleOrDefault != null ? singleOrDefault.Location : 0; } } } Update : public class PlacementLocations { #region Variables private readonly List _placementLocations;

No comments:

Post a Comment