
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How do we use enum keyword to define a variable type in C#?
C# enumerations are value data type. An enumeration is a set of named integer constants. An enumerated type is declared using the enum keyword.
The following is the syntax of enum.
enum <enum_name> { enumeration list };
Let us see an example.
enum Vehicle { Car, Bus, Truck };
The following is an example showing how to use enum keyword to define variable type.
Example
using System; namespace Demo { class Program { enum Days { Sun, Mon, tue, Wed, thu, Fri, Sat }; static void Main(string[] args) { int WeekdayStart = (int)Days.Mon; int WeekdayEnd = (int)Days.Fri; Console.WriteLine("Monday: {0}", WeekdayStart); Console.WriteLine("Friday: {0}", WeekdayEnd); Console.ReadKey(); } } }
Output
Monday: 1 Friday: 5
- Related Articles
- How do we use an enum type with a constructor in Java?\n
- How to define an enumerated type (enum) in C++?
- How to convert an enum type variable to a string in C++?
- Why do we use internal keyword in C#?
- Why do we use the params keyword in C#?
- How do we initialize a variable in C++?
- How do we use function literal to define a function in JavaScript?
- How to define a variable in C++?
- Can we define an enum inside a class in Java?
- Can we define an enum inside a method in Java?
- What is MySQL ENUM data type? What are the advantages to use ENUM data type?
- How do we use a #line directive in C#?
- How do we declare variable in Python?
- How can we create and use ENUM columns in MySQL?
- How to define a variable in HTML5?

Advertisements