的類型,我有這樣的代碼:限制一個基類參數
public static void ToUpperCase(params Control[] controls)
{
foreach (Control oControl in controls)
{
if (oControl is TextBox)
{
oControl.TextChanged += (sndr, evnt) =>
{
TextBox txtControl = sndr as TextBox;
int pos = txtControl.SelectionStart;
txtControl.Text = txtControl.Text.ToUpper();
txtControl.SelectionStart = pos;
};
}
else if (oControl is ComboBox)
{
oControl.TextChanged += (sndr, evnt) =>
{
ComboBox cmbControl = sndr as ComboBox;
int pos = cmbControl.SelectionStart;
cmbControl.Text = cmbControl.Text.ToUpper();
cmbControl.SelectionStart = pos;
};
}
else throw new NotImplementedException(oControl.GetType().DeclaringType.ToString() + " is not allowed.");
}
}
我想限制params Control[] controls
只接受一個TextBox
和ComboBox
類型。
我的代碼是在C#中,框架4,構建在VS2010Pro中,項目在WinForms中。
請幫忙。提前致謝。
獨佔一個或另一個 - 如在,它將是一個TextBoxes數組或一個ComboBoxes數組?或者它可能是一個TextBoxes和ComboBoxes數組? – Zenexer 2012-02-08 01:54:40