xxxxプログラマのメモ

先人に感謝と敬意

型によるSwitch #switch by object type

条件分岐 - C# によるプログラミング入門 | ++C++; // 未確認飛行 C

                switch (inputControl)
                {
                    case NumberTextbox _:
                        break;
                    case TextBox _ when string.IsNullOrWhiteSpace(inputControl.Text):
                        isValid = false;
                        lblControl.ForeColor = ColorDefs.AlertForeColor;
                        break;
                    case TextBox _:
                        lblControl.ForeColor = tableLayoutPanel.Parent.ForeColor;
                        break;
                    case ComboBox box when box.SelectedIndex < 0:
                        isValid = false;
                        lblControl.ForeColor = ColorDefs.AlertForeColor;
                        break;
                    case ComboBox box:
                        lblControl.ForeColor = tableLayoutPanel.Parent.ForeColor;
                        break;
                }

Thanks!