Main Menu

HOME

.Net
ASP
Assembly
C
C++
Delphi
HTML
Java
JavaScript
MySQL
PC interface
Powershell
Perl
PHP
VBScript
Visual Basic
XML

Make money selling software. Check this out here

Hosted clickbank mall. Check this out here


Sedo - Buy and Sell Domain Names and Websites project info: programmershelp.co.uk Statistics for project programmershelp.co.uk etracker® web controlling instead of log file analysis

   Misc

   Amazon

   Links

Enumerations in C#


 

An enumeration is a data type that enumerates a set of items by assigning to each of them an identifier (a name), while exposing an underlying base type for ordering the elements of the enumeration. The underlying type is int by default, but can be any one of the integral types except for char.

Enumerations are declared as follows:

enum Weekday { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday };
                                          

The elements in the above enumeration are then available as constants:

Weekday day = Weekday.Monday;
if (day == Weekday.Tuesday)
{
    Console.WriteLine("Time sure flies by when you program in C#!");
}
                                          

If no explicit values are assigned to the enumerated items as the example above, the first element has the value 0, and the successive values are assigned to each subsequent element. However, specific values from the underlying integral type can be assigned to any of the enumerated elements:

enum Age { Infant = 0, Teenager = 13, Adult = 18 };

Age age = Age.Teenager;
Console.WriteLine("You become a teenager at an age of {0}.", age.ToString());
                                          

The underlying values of enumerated elements may go unused when the purpose of an enumeration is simply to group a set of items together, e.g., to represent a nation, state, or geographical territory in a more meaningful way than an integer could. Rather than define a group of logically related constants, it is often more readable to use an enumeration.

It may be desirable to create an enumeration with a base type other than int. To do so, specify any integral type besides char as with base class extension syntax after the name of the enumeration, as follows:

enum CardSuit : byte { Hearts, Diamonds, Spades, Clubs };
                                          

 

All text is available under the terms of the GNU Free Documentation License
Source : Wikibooks


 

 



 




   Sponsors
 

   Software
500 Java Tips E-book
PHP editor
PERL editor
Beginning Java
Beginning Visual Basic
Learn VB.net
Learn VB 6
VB and databases
ASP image library
C++ builder programming
C++ fundamentals

   Source Code
bytes to whatever(VB)
Slashdot feed(PHP)
populate a select menu from MySQL(PHP)
Random image example(PHP)
Using the SubString method(VB.net)
free disk space(PHP)
Is a number odd or even(C Sharp)
text alignment(CSS)




Copyright © 2004 by programmershelp.co.uk