Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of #region and #endregion in C#?

Tags:

c#

Give me an example of what can be achieved if I use a region block, and what is the use behind the wording after the region declaration?

#region MyClass definition
//Some code
#endregion
like image 481
Suraj Khanra Avatar asked Sep 05 '25 13:09

Suraj Khanra


1 Answers

There is no (technical) reason to use #region.

The only thing it does is provide an easy way to collapse code.

As an example, for a relatively bulky class; I tend to separate some things in different regions:

  • Constructors and properties
  • Private or protected methods
  • Public methods.

That's just one example. You can separate code however you want, it has no effect on how the application works.

like image 170
Flater Avatar answered Sep 10 '25 04:09

Flater