Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

C# equivalent of VB's With keyword

, 27 May 2011
Rate this:
Please Sign up or sign in to vote.
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

dzCepheus
Web Developer
United States United States
No Biography provided

Comments and Discussions

 
GeneralReason for my vote of 5 exactly what I thought Pinmemberjohannesnestler15-Feb-12 3:40 
GeneralReason for my vote of 5 Yep, thats what I do too. Having the... PinmemberDoc Lobster24-Sep-11 0:14 
GeneralIt'd be an essentially useless addition, but It'd be interes... PinmemberdzCepheus27-May-11 7:30 
GeneralI don't like creating needless delegates; to my mind, simply... Pinmembersupercat927-May-11 5:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 27 May 2011
Article Copyright 2011 by dzCepheus
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid