Search code examples
c#region

What is the symbol # used for in C#


I'm not that experienced with programming and I encountered the # symbol in a piece of C# code. So what is the # used for in #region?

public class DatabaseIndex : IComparable<DatabaseIndex>, INotifyPropertyChanged
    {
        #region DataBaseIndex
        public DatabaseIndex(DatabasePackedFile owner)
        {
            this.Owner = owner;
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String propertyName = "")
        {
        ...
        }

Solution

  • It's used to denote preprocessor directives, in this case defining a block of code that can expand/collapse when using visual studio, to make it easier to maintain for future developer.

    You can read more about them here: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives/