
- 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
C# Enum Parse Method
The Parse method in Enum converts the string representation of the name or numeric value of enum constants to an equivalent enumerated object.
The following is our enumeration.
enum Vehicle { Car, Bus, Truck, Motobike };
Now, use the GetNames() method in a loop to get the enum values. Parse them using the Enum.Parse() method as shown below −
Enum.Parse(typeof(Vehicle)
Example
using System; public class Demo { enum Vehicle { Car, Bus, Truck, Motobike }; public static void Main() { Console.WriteLine("The enumeration..."); foreach (string v in Enum.GetNames(typeof(Vehicle))) { Console.WriteLine("{0} = {1:D}", v, Enum.Parse(typeof(Vehicle), v)); } Console.WriteLine(); } }
Output
The enumeration... Car = 0 Bus = 1 Truck = 2 Motobike = 3
- Related Articles
- C# Enum IsDefined Method
- C# Enum ToString() Method
- C# Enum TryParse() Method
- C# Enum CompareTo Method
- C# Enum Equals Method
- C# Enum Format Method
- C# Enum GetName Method
- C# Enum GetNames Method
- C# Enum GetValues Method
- JavaScript JSON parse() Method
- Instant parse() method in Java
- LocalDate parse() method in Java
- LocalDateTime parse() method in Java
- Period parse() method in Java
- LocalTime parse() method in Java

Advertisements