Monday, April 30, 2012

Enumerations


Enumerations are types that inherit from System.Enum. The elements of an enumeration
are expressed in words rather than numbers, which makes it convenient for understanding
the meaning of the value being used. Enumerations symbolically represent a set of values
of one of the primitive integral types.
The type of the elements of an enumeration can be byte, short, int or long. If no type is
specified explicitly, the default type is int.

Example:
enum month : byte
{Jan = 2, Feb = 5, Mar = 10};


Explanation:
In the above code segment, an enumeration type month is declared. The underlying type
of the elements has been specified as byte. It has three elements viz: Jan, Feb and Mar.
These three elements have been assigned specific values. In case of an enumeration, if no
values are specified, the value of the first element corresponds to 0 and so on.

No comments:

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...