On Thu, 17 Jul 2008 18:24:06 -0700, Joseph
<Jo****@discussions.microsoft.comwrote:
I would like to know how to implement several Radiobuttons using the
Switch
statement instead of If/Else conditional statement. For instance, if I
have
the following:
Well, as you have probably already seen, you can't use your RadioButton
reference as the parameter for a switch() statement.
You didn't show the rest of the code, so it's hard to know what you're
actually trying to do. However, typically you'd be trying to do something
in response to changes in the button state. For that, it seems to me that
the most straight-forward way is to just handle the CheckedChanged event.
Use a different handler for each button, where each handler has the
button-specific code you desire.
Other alternatives include:
-- store a "switchable" value in the Tag property for the button
-- store a delegate specific to each button in the Tag property
-- store the button control references in an array, using the index of
each button as your "switchable" value, and simply enumerating the array
to determine the correct index (see Array.IndexOf())
If none of those ideas seem useful, you'll probably have to ask a more
specific question, with details that actually explain what you're trying
to do.
Pete