asp.net.ph

Enum.ToString Method

System Namespace   Enum Class


Converts the value of this instance to its equivalent string representation.

Overload List

Converts the value of this instance to its equivalent string representation.

Converts the value of this instance to its equivalent string representation using the specified format information.

Converts the value of this instance to its equivalent string representation using the specified format.

Converts the value of this instance to its equivalent string representation using the specified format and format information.


Example

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

NOTE: This example shows how to use one of the overloaded versions of ToString. For other examples that might be available, see the individual overload topics.

[ VB ] 
Imports System

Public Class EnumSample    
    Enum Colors
        Red = 1
        Blue = 2
    End Enum
    
    Public Shared Sub Main ( ) 
        Dim myColors As Colors = Colors.Red
        Response.WriteLine ( "The value of this instance is '{0}'", _
           myColors.ToString ( ) ) 
    End Sub
End Class

'Output.
'The value of this instance is 'Red'.

[ C# ] 
using System;

public class EnumSample {
    enum Colors {Red = 1, Blue = 2};
    
    public static void Main ( ) {
        Enum myColors = Colors.Red;
        Response.WriteLine ( "The value of this instance is '{0}'",
           myColors.ToString ( ) );
    }
}
/*
Output.
The value of this instance is 'Red'.
*/

[ C++, JScript ] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

Enum Members Skip Navigation Links




Previous page Back to top Next page

Check out related books at Amazon

© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note