System Namespace Enum Class
Converts the value of this instance to its equivalent string representation.
[ VB ]
<Serializable>
Overrides Overloads Public Function ToString ( ) As String
[ C# ]
[Serializable]
public override string ToString ( );
[ C++ ]
[Serializable]
public: String* ToString ( );
[JScript ]
public Serializable
override function ToString ( ) : String;
The string representation of the value of this instance.
This method works as if the general format character, "G", were specified. That is, if the FlagsAttribute is not applied to this enumerated type and there is a named constant equal to the value of this instance, then the return value is a string containing the name of the constant. If the FlagsAttribute is applied and there is a combination of one or more named constants equal to the value of this instance, then the return value is a string containing a delimiter-separated list of the names of the constants. Otherwise, the return value is the string representation of the numeric value of this instance.
For more information about format characters, see the Remarks section of the Format method. For more information about formatting in general, see Formatting Overview.
The following code example demonstrates converting an enumerated value to a string.
[ 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 in the upper-left corner of the page.
Enum Members Enum.ToString Overload List Format Parse