Boolean variables or Windows.Forms checkboxes?

A

Alex Moskalyuk

In the GUI application I am writing I have some checkboxes for various
settings. The code right now has internal boolean variables and the events
that are fired off on checkBox_CheckedChanged for different checkboxes
change those boolean variables, which are later used throughout the program
(if/else statements).

Looking at this, I could cut the overhead of storing and retrieving the
boolean value by just referring to checkBox1.Checked property each time I
need to find out the value.

Is there any overhead involved with accessing boolean properties of the
Windows Form (the values are accessed perhaps 10-50 times a second) as
opposed to storing the boolean internally as a variable?
 
N

Nicholas Paldino [.NET/C# MVP]

Alex,

Accessing the internal variable is probably much quicker. For the
checkbox, what most likely occurs is that a message is sent to the window to
determine the checked state. This requires more than a few function calls.

I'd recommend checking the field directly.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top