keyword in C#, like Visual Basic. So you end up writing code like this:
Here’s a workaround to this:
This saves you repeatedly typing the same class instance or control name over and over again. It also makes code more readable since it clearly says that you are working with a progress bar control within the block. It you are setting properties of several controls one after another, it’s easier to read such code this way since you will have dedicated block for each control.
It’s a very simple one line extension method that enables it:
You could argue that you can just do this:
But it’s not elegant. You are introducing a variable “
” in the local scope of the whole function. This goes against naming conventions. Morever, you can’t limit the scope of “
” within a certain place in the function.