المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Which one is better, forcing an enabled=true at each call or check it with an if statement?



C# Programming
09-26-2009, 03:28 AM
Hello,

In a professional view, which one of the below does the least cycling?

Assume these two lines of code in a button's click event and i want blabla control's enabled property to be set true at the click of the button:

1) blabla.Enabled=true;

2) if(!blabla.Enabled) blabla.Enabled=true;

First one will force an Enabled=true at every button click even if it was already true. (Or maybe there is a logic beneath that I don't know, like the framework checks it and does the work, in this case, the question is irrelevant)

Second one will first check if it is false and then set true. This one will not always run the code but instead it will do an IF check.

So the question again, is: Which one is better for CPU? (Or in another sentence: Does IF or Enabled property uses more cycle?)

Thanks in advance.

Best regards,
An?l Y?ld?z.