Use this space to put some text. Update this text in HTML

468x60 banner ad

Advertise with Us

Powered by Blogger.

Saturday, 9 April 2016

Csharp Region


#region (C# Reference)

#region lets you specify a block of code that you can expand or collapse when using the outlining feature of the Visual Studio Code Editor.


 In longer code files, it is convenient to be able to collapse or hide one or more regions so that you can focus on the part of the file that you are currently working on.


The following example shows how to define a region:

   #region Method For Add and Substract
    private int A, B, C;
    public int SumAbcMethod()
    {
        return A + B + C;
    }
    public int SubstractAbcMethod()
    {
        return B + C;
    }
    #endregion
    #region Method For Add and Substract

    public int MultiplayAbcMethod()
    {
        return A * B * C;
    }
    public int DivideAbcMethod()
    {
        return B / C;
    }
    #endregion

Note: 


A #region block must be terminated with a #endregion directive.


A #region block cannot overlap with a #if block. However, a #region block can be nested in

 a #if block, and a #if block can be nested in a #region block.

Collapse region:






Advantage:
The method was pretty clear to understand by looking at the region names. This being said, the same method once refactored would be as clear as the original.

Disadvantage:

It wasn't obvious if there were dependencies between the regions. Hopefully, there were no reuse of variables; otherwise, the maintenance could be a nightmare even more.
The method was nearly impossible to test. How would you easily know if the method which does twenty things at a time does them correctly?




No comments :

Post a Comment

Ask a Question?