C# Enum ToString()

Description

Enum ToString() converts the value of this instance to its equivalent string representation.

Syntax

Enum.ToString() has the following syntax.


public override string ToString()

Returns

Enum.ToString() method returns The string representation of the value of this instance.

Example

The following example demonstrates converting an enumerated value to a string.


//w  w w. j av  a  2 s. c om
using System;

public class EnumSample {
    enum Colors {Red = 1, Blue = 2};

    public static void Main() {
        Enum myColors = Colors.Red;
        Console.WriteLine("The value of this instance is '{0}'",
           myColors.ToString());
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version