Portioning code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lukas Dissing
    New Member
    • Nov 2011
    • 2

    #1

    Portioning code

    Hello.

    I have a simple question which internet can't seem to answer (likely because I can't remember the correct term).

    It's been a while since I used c# but I remember there to be some kind of tag that lets you "portion" a chunk of code and minimize it just like a function.

    Say you have code that looks something like this:


    // A-related
    // A variables

    lots of variables...

    // A functions

    lots of functions...


    And you want to minimize to a single line while working (like visual lets you do for functions).

    Like this:

    [+] A related

    Expanded:

    [-] A related
    // A variables

    lots of variables...

    // A functions

    lots of functions...
    [-] /end A related

    I know this might seem trivial, but as my code grows longer and longer I want to be able to navigate it without wearing out the scroll wheel on my mouse.

    Thank you.
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    I think what you're looking for is the region tags. You start one with #region and end it with #endregion. You can put text after the #region to identify that region in the environment.

    For example...

    Code:
    public class Test
    {
      #region Private Members
      private bool m_flag;
      private string m_id;
      #endregion
    
      #region Constructor(s)
      public Test(bool statusFlag, string id)
      {
        #region Member Variable Assignment
        m_flag = statusFlag;
        m_id = id;
        #endregion
    
        Console.WriteLine("Constructor finished.");
      }
      #endregion
    }
    For extra functionality, right-click your code and check out the Outlining menu options.

    Comment

    • Lukas Dissing
      New Member
      • Nov 2011
      • 2

      #3
      Yes!

      Thank you very much.

      Comment

      Working...