Is the #region directive really useful in .NET?

后端 未结 17 2075
孤城傲影
孤城傲影 2021-01-03 23:43

After maintaining lots of code littered with #region (in both C# and VB.NET), it seems to me that this construct is just a bunch of \"make work\" for the programmer. It\'s w

17条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-04 00:32

    I use them all the time. Again, like anything else, they can be used for both evil and good, and can certainly be the hallmark of bad design, but they can be used to help organize code very well.

    #region Properties
    
    #region Update Section
    
    #region Accessors
    

    Certainly you should avoid Jeff's example of

    #Sweep under carpet
    

    What I find odd about them, as Jeff pointed out, is that they are a compiler preprocessor command for ui purposes. I'm sure VS team could have done something just as useful in another way.

提交回复
热议问题