|
-
Feb 27th, 2011, 11:14 PM
#7
Re: Dynamically accessing Variables
The two buttons can have the same click event handler, but at some point you have to have a condition (an If statement) because at some point the code will not be quite the same. You end up with two choices. The first choice is to have different code for the two different buttons, which is what you showed in version 1. The second choice is to have a conditional switch, which is what Edgemeal suggested. This has nothing to do with the language, as it will be true in any language. At some point, the code has to know which variable it is to use unless one set of code uses one variable and the other set of code uses the other variable.
There is a very rare case where you can avoid this, but it will only work for some simple addition or subtraction and booleans. The case is so rare that it is hardly worth mentioning, but I figured I might as well be complete. In that rare case, you are actually performing both operations, but one has no effect on the result, and which one has no effect depends on the variables themselves. It's also not worth doing in .NET.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|