asp.net.ph

Enum.Format Method

System Namespace   Enum Class


Converts the specified value of a specified enumerated type to its equivalent string representation according to the specified format.

[ VB ]
<Serializable>
Public Shared Function Format ( _
   ByVal enumType As Type, _
   ByVal value As Object, _
   ByVal format As String _
) As String

[ C# ]
[Serializable]
public static string Format (
   Type enumType,
   object value,
   string format
);

[ C++ ]
[Serializable]
public: static String* Format (
   Type* enumType,
   Object* value,
   String* format
);

[JScript ]
public Serializable
static function Format (
   enumType : Type,
   value : Object,
   format : String
) : String;

Parameters

enumType
The enumeration type of the value to convert.
value
The value to convert.
format
The output format to use.

Return Value

A string representation of value.

Exceptions


Exception Type Condition
ArgumentNullException The enumType, value, or format parameter is a null reference ( Nothing in Visual Basic ).
ArgumentException The enumType parameter is not an Enum type.

-or-

The value is from an enumeration that differs in type from enumType.

-or-

The type of value is not an underlying type of enumType.

FormatException The format parameter contains an invalid value.

Remarks

The valid format values are:

Format Description
"G" or "g" If value is equal to a named enumerated constant, the name of that constant is returned; otherwise, the decimal equivalent of value is returned.

For example, suppose the only enumerated constant is named, Red, and its value is 1. If value is specified as 1, then this format returns "Red". However, if value is specified as 2, this format returns "2".

-or-

If the FlagsAttribute custom attribute is applied to the enumeration, then value is treated as a bit field that contains one or more flags that consist of one or more bits.

If value is equal to a combination of named enumerated constants, a delimiter-separated list of the names of those constants is returned. value is searched for flags, going from the flag with the largest value to the smallest value. For each flag that corresponds to a bit field in value, the name of the constant is concatenated to the delimiter-separated list. Then the value of that flag is excluded from further consideration, and the search continues for the next flag.

If value is not equal to a combination of named enumerated constants, the decimal equivalent of value is returned.

"X" or "x" Represents value in hexadecimal without a leading "0x".
"D" or "d" Represents value in decimal form.
"F" or "f" Treats value as a bit field. If value is equal to a combination of named enumerated constants, a delimiter-separated list of the names of those constants is returned. Parameter value is searched for flags, going from the flag with the largest value to the smallest value. For each flag that corresponds to a bit field in value, the name of the constant is concatenated to the delimiter-separated list. Then the value of that flag is excluded from further consideration, and the search continues for the next flag.

If value is not equal to a combination of named enumerated constants, the decimal equivalent of value is returned.


See Also

Enum Members   ToString Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

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

You can help support asp.net.ph