I'm making a 7-segment clock in C# and I've come across a problem. I usually code in PHP and this problem is confusing to me.
Let's say I'm trying to assign locations to panels in C# So first use this code:
Panel a = new Panel();
Panel b = new Panel();
Panel c = new Panel();
Panel d = new Panel();
Panel e = new Panel();
Panel f = new Panel();
Panel g = new Panel();
I have an array:
int[,] locationArray = new int[,] {
{10,20},
{90,30},
{90,125},
{10,210},
{5,125},
{5,30},
{10,115}
};
Than I loop through that array:
for (int d = 0; d < locationArray.GetLength(0); d++)
{
for (int j = 0; j < locationArray.GetLength(1); j++)
{
int locationY = locationArray[i, j];
int locationX = locationArray[i, 0];
/* a has to be variable so that I could use one of the panels from a to g. */
a.Location = new Point(locationX, locationY);
}
}
So is it possible to make a.Location a variable from a to g without making it complicated/messy like a switch case or if statement.
I wanted to just iterate through an array above the first array to choose the letter. But it doesn't seem to work that way.
var panels = new[] { a, b, c, ... };. Then dopanels[i].Location = new Point.... You also may not need to assign variables to them, so you could just dovar panels = new[] { new Panel(), new Panel(), ..., new Panel() };var panels = Enumerable.Range(1,7).Select(e => new Panel()).ToList();