Write a class with some properties and indexed
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
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
public class PlacementLocation
{
private int Row { get; set; }
private int Column { get; set; }
private int Location { get; set; }
private void SetLocationInList()
{
_placementLocations = new List<PlacementLocation>
{
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<PlacementLocation> _placementLocations;
public PlacementLocation()
{
_placementLocations = new List<PlacementLocation>();
SetLocationInList();
}
public Tuple<int, int> this[int location]
{
get { return new Tuple<int,
int>(_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;
}
}
}
No comments:
Post a Comment