#192 – Using Non-Default Constant Values for Enumeration Members

When you define an enum type, the members contained in your enumeration take on constants starting at zero (for the first member) and then incrementing by one (for consecutive members).

        public enum Mood {
            Crabby,       // 0
            Happy,        // 1
            Petulant,     // 2
            Elated };     // 3

You can, however, specify the constant value to use for each member.  You can specify constants in any order.  Members that don’t have a value specified take on a value one greater than the previous member.

        public enum Mood { 
            Crabby = -5,       
            Happy = 5,        
            Petulant = -2,     
            Elated = 10};

        public enum Weekday
        {
            Sunday = 1,
            Monday,     // 2
            Tuesday,    // 3, etc.
            Wednesday,
            Thursday,
            Friday,
            Saturday
        };

#187 – Everything Is an Object

In C#, every data item is an object, created on the stack or the heap.  Even built-in data types, like double or int represent classes (System.Double and System.Int32) and declaring an object to be of one of these types is equivalent to instantiating an object of the appropriate type.

            // Declare and instantiate an int
            int i = 12;

            // Equivalent to
            System.Int32 i2 = new System.Int32();
            i2 = 12;

Similarly, every function call involves calling a method declared in some type–either a static or an instance method.

Even constants represent instances of some object.