Click here to Skip to main content
12,349,752 members (27,564 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

5.2K views
1 bookmarked
Posted

C# equivalent of VB's With keyword

, 27 May 2011 CPOL
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)

Share

About the Author

dzCepheus
Web Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

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

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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 | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 27 May 2011
Article Copyright 2011 by dzCepheus
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid