
- 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 ToString() Method
The ToString() method converts the value of this instance to its equivalent string representation.
Firstly, set an enum.
enum Vehicle { Car, Bus, Truck, Motobike };
To convert it to an equivalent string representation, use ToString().
Vehicle.Car.ToString("d")
Example
using System; public class Demo { enum Vehicle { Car, Bus, Truck, Motobike }; public static void Main() { Console.WriteLine("Vehicle.Car = {0}", Vehicle.Car.ToString("d")); Console.WriteLine("Vehicle.Bus = {0}", Vehicle.Bus.ToString("d")); } }
Output
Vehicle.Car = 0 Vehicle.Bus = 1
- Related Articles
- C# Int16.ToString() Method
- Int64.ToString() Method in C#
- C# Enum IsDefined Method
- C# Enum Parse 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
- Java toString() method.
- UInt32.ToString() Method in C# with Examples
- UInt16.ToString Method in C# with Examples
- UInt64.ToString() Method in C# with Examples

Advertisements