Ask the Expert

#region blocks are being put into my code by the VS.NET wizards, but I have no idea what they're for

#region blocks are being put into my code by the VS.NET wizards, but I have no idea what they're for. Help me!
Don't panic. The VS.NET code editor window knows how to collapse and expand certain regions of your code with little plus and minus signs in the margins. This feature is called outlining and allows you to, for example, collapse the entire implementation of one class while you're concentrating on another one. However, only certain constructs can be outlined, like classes, namespaces and methods.

For other things, like a group of event handler methods, you can define a custom group for outlining using a region, defined using the #region/#endregion directives. For example, the Implement Interface feature of VS.NET produces a region for the method implementations labeled " Methods." Collapsed, it looks like this:

class MyClass : IDisposable
{
       IDisposable Members
}

There are a number of operations that can be performed on a region of outlined code, as shown in the Edit -> Outlining menu:

  • Toggle Outline Expansion: Expand or collapse the current region.
  • Toggle All Outline: Expand or collapse the current file.
  • Stop Outlining: Turn off the outlining feature for all text files.
  • Collapse To Definitions: Hide all code and show just namespace, class and member definitions.

    This was first published in October 2002

  • There are Comments. Add yours.

     
    TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

    REGISTER or login:

    Forgot Password?
    By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
    Sort by: OldestNewest

    Forgot Password?

    No problem! Submit your e-mail address below. We'll send you an email containing your password.

    Your password has been sent to: