Question

I assume #region is ignored and dropped by the compiler, so why is it a preprocessor directive rather than some kind of comment structure (like //REGION NAME: stuff(); //ENDREGION NAME or something.) Is there a particular reason the decision to make it a directive was made?

Was it helpful?

Solution

I know it's not a direct answer but that's how it's laid out in the C# Language Spec (§2.5).

The pre-processing directives provide the ability to conditionally skip sections of source files, to report error and warning conditions, and to delineate distinct regions of source code.

I don't think it's ignored by the compiler, it just doesn't have any effect. It's still considered a conditional compilation from the lexical processing point of view and, therefore, in line with some of the other pre-processing directives. From the spec:

The lexical processing of a region:

#region

...

#endregion

corresponds exactly to the lexical processing of a conditional compilation directive of the form:

#if true

...

#endif

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top