我正在制作一个小工具。我只想知道switch
下面的代码中是否是实现这一目标的最快/最佳方法?在 PHP 中,我会像动态地引用变量名$Stop{int Stop} -> $BackColor = "Color"
public void Populate(Color Color, int Stop)
{
Colour.BackColor = Color; // Bottom left - PictureBox
Hex.Text = ARGBToHex(Color.ToArgb()); // Hex (#703919) - TextBox
Red.Text = Color.R.ToString(); // Red (153) - TextBox
Green.Text = Color.G.ToString(); // Green (180) - TextBox
Blue.Text = Color.B.ToString(); // Blue (209) - TextBox
Alpha.Text = "100"; // Alpha (100) - TextBox
StopText.Text = Stop.ToString(); // Read-only (1) - TextBox
switch(Convert.ToInt16(StopText.Text))
{
case 1: Stop1.BackColor = Color; break; // Small light blue rectangle - PictureBox
case 2: Stop2.BackColor = Color; break; // Small dark blue rectangle - PictureBox
}
}