C# equivalent of VB's With keyword
You can limit the scope of 'p' inside your function:private void Whatever() { DoStuffHere(); // 'p' is not in scope. { var p = this.StatusProgressBar; // 'p' is in scope. p.IsIndeterminate = false; p.[etc] } // 'p' is not in...
You can limit the scope of '
p
' inside your function:
private void Whatever() { DoStuffHere(); // 'p' is not in scope. { var p = this.StatusProgressBar; // 'p' is in scope. p.IsIndeterminate = false; p.[etc] } // 'p' is not in scope. DoMoreHere(); }Notice the open and close braces - they create a scope that '
p
' will not be leaked from.
Personally, I like your idea better - but it *is* possible to limit scope within a function.