I want to avoid the kludginess of:
private void listBoxBeltPrinters_SelectedIndexChanged(object sender, System.EventArgs e)
{
string sel = string listBoxBeltPrinters.SelectedItem.ToString();
if (sel == "Zebra QL220")
{
PrintUtils.printerChoice = PrintUtils.BeltPrinterType.ZebraQL220;
}
else if (sel == "ONiel")
{
PrintUtils.printerChoice = PrintUtils.BeltPrinterType.ONiel;
}
else if ( . . .)
}
Is there a way I can more elegantly or eloquently assign to an enum based on a list box selection, something like:
PrintUtils.printerChoice = listBoxBeltPrinters.SelectedItem.ToEnum(PrintUtils.BeltPrinterType)?
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…