W e b t u t o r i a l s

Visual Studio.NET IDE

Define C#.NET

C# Comment

C# Variables

C# Data Types

C# Escape Sequence

C# Operators

Exercise-1

Format String

Operator Precedence

C# Keywords

Constant Variable

Type Conversion

Flow Control

Exercise on Loops and Nested Loop

C# Arrays

C# Strings

User-Define Methods

Variable Scope

C# Enumerations

C# Structure

C# Exception Handling

Object Oriented Programming

C# Classes

C# Constructor & Destructor

C# Inheritance

C# Polymorphism

C# Operator Overloading

C# Interface

Abstract Classes, Abstract Methods

Sealed Classes, Methods

C# Properties

C# Indexer

C# Delegates

C# Generics

C# Collection

System.Object

Enumerations

Enumerations are special sets of names which are mapped with the numbers, usually integers. The enum keyword is used to declare an enumeration.

    Syntax:
    Enum typename
    {
        value1,
        value2,
        value3,
        ...
    }

    Example 1:
    namespace ConsoleApplication1
    {
        public enum Days { Monday, Tuesday, Wednesday, Thursday, Friday, 
        Saturday, Sunday }

        class Program
        {
            static void Main(string[] args)
            {
                Days day = Days.Monday;
                Console.WriteLine((int)day);
                Console.ReadLine();
            }
        }
    }
    Note: enum can be declared inside or outside a class.

    Example 2:
    namespace ConsoleApplication1
    {
        enum Days : int  { Sat = 1, Sun, Mon, Tue, Wed, Thu, Fri };
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine((int) Days.Mon );
                Console.Read();
            }
        }
    }
    

Note: enum data type is usually use sbyte, byte, short,ushort, int, uint, long, ulong data types only. Decimal data types cannot be used.