Professional Documents
Culture Documents
Enumeration
Enumeration is a user-defined integer type which provides a way for attaching names to numbers. The enum keyword automatically enumerates a list of words by assigning them values 0,1,2 and so on.
Enumeration Example
enum shape {
Circle, Square, Triangle
} This can be written in one line as follows: enum Shape {Circle,Square,Triangle} Here, Circle has the value 0, Square has the value 1 and Triangle has the value 2.
Example Program
using System; class EnumDemo { enum Apple{Jonathan, GoldenDel, RedDel, Winesap,Cortland,McIntosh}; static void Main() { string[] color = { "Red", "Yellow", "Red", "Red", "Red", "Reddish Green" }; Apple i;
} }
Example Program
for(i=Apple.Jonathan; i<=Apple.McIntosh;i++){ Console.WriteLine(i + has value of + (int)i); for(i=Apple.Jonathan; i<=Apple.McIntosh;i++){ Console.WriteLine(Color of + i + is + color*(int)i] );
Use Enumerations
Using System; Class ConveyorControl {
Public enum Action{Start,Stop,Forward,Reverse}; Public void Conveyor(Action com) {
switch(com) {
Case Action.Start: Console.WriteLine(Starting Conveyor); break; Case Action.Stop: Console.WriteLine(Stopping Conveyor); break;
Use Enumerations
class ConveyorDemo {
static void Main() {
ConveyorControl c= new ConveyorControl(); c.Conveyor(ConveyorControl.Action.Start); c.Conveyor(ConveyorControl.Action.Stop);
Encapsulation
Encapuslation provides the ability to hide th