[Serializable] |
Enum provides methods to compare instances of this class, convert the value of an instance to its string representation, convert the string representation of a number to an instance of this class, and create an instance of a specified enumeration and value.
You can also treat an Enum as a bit field. For more information, see FlagsAttribute.
This class inherits from ValueType, and implements the IComparable, IFormattable, and IConvertible interfaces. Use the Convert class for conversions instead of this class' explicit interface member implementation of IConvertible.
CompareTo | Compares this instance to a specified object and returns an indication of their relative values. |
Equals | Overridden: Returns a value indicating whether this instance is equal to a specified object. |
Format | Converts the specified value of a specified enumerated type to its equivalent string representation according to the specified format. |
GetHashCode | Overridden: Returns the hash code for this instance. |
GetName | Retrieves the name of the constant in the specified enumeration that has the specified value. |
GetNames | Retrieves an array of the names of the constants in a specified enumeration. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
GetTypeCode | Returns the underlying TypeCode for this instance. |
GetUnderlyingType | Returns the underlying type of the specified enumeration. |
GetValues | Retrieves an array of the values of the constants in a specified enumeration. |
IsDefined | Returns an indication whether a constant with a specified value exists in a specified enumeration. |
Parse | Overloaded:Parse(Type enumType, string value) Converts the string representation of the name or numeric value of one or more enumerated constants to an equivalent enumerated object. |
Parse | Overloaded:Parse(Type enumType, string value, bool ignoreCase) Converts the string representation of the name or numeric value of one or more enumerated constants to an equivalent enumerated object. A parameter specifies whether the operation is case-sensitive. |
ToObject | Overloaded:ToObject(Type enumType, byte value) Returns an instance of the specified enumeration type set to the specified 8-bit unsigned integer value. |
ToObject | Overloaded:ToObject(Type enumType, short value) Returns an instance of the specified enumeration type set to the specified 16-bit signed integer value. |
ToObject | Overloaded:ToObject(Type enumType, int value) Returns an instance of the specified enumeration type set to the specified 32-bit signed integer value. |
ToObject | Overloaded:ToObject(Type enumType, long value) Returns an instance of the specified enumeration type set to the specified 64-bit signed integer value. |
ToObject | Overloaded:ToObject(Type enumType, object value) Returns an instance of the specified enumeration set to the specified value. |
ToObject | Overloaded:ToObject(Type enumType, sbyte value) Returns an instance of the specified enumeration type set to the specified 8-bit signed integer value. |
ToObject | Overloaded:ToObject(Type enumType, ushort value) Returns an instance of the specified enumeration type set to the specified 16-bit unsigned integer value. |
ToObject | Overloaded:ToObject(Type enumType, uint value) Returns an instance of the specified enumeration type set to the specified 32-bit unsigned integer value. |
ToObject | Overloaded:ToObject(Type enumType, ulong value) Returns an instance of the specified enumeration type set to the specified 64-bit unsigned integer value. |
ToString | Overloaded:ToString() Overridden: Converts the value of this instance to its equivalent string representation. |
ToString | Overloaded:ToString(IFormatProvider provider) Converts the value of this instance to its equivalent string representation using the specified format information. |
ToString | Overloaded:ToString(string format) Converts the value of this instance to its equivalent string representation using the specified format. |
ToString | Overloaded:ToString(string format, IFormatProvider provider) Converts the value of this instance to its equivalent string representation using the specified format and format information. |
ctor #1 | Default constructor. This constructor is called by derived class constructors to initialize state in this type. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
protected Enum(); |
target
Return Value | Description |
---|---|
Less than zero | The value of this instance is less than the value of . |
Zero | The value of this instance is equal to the value of . |
Greater than zero | The value of this instance is greater than the value of target. -or- target is null. |
Exception Type | Condition |
---|---|
ArgumentException | target and this instance are not the same type. |
InvalidOperationException | This instance is not type SByte, Int16, Int32, Int64, Byte, UInt16, UInt32, or UInt64. |
obj
~Enum(); |
enumType
value
format
Exception Type | Condition |
---|---|
ArgumentNullException | The enumType, value, or format parameter is null. |
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. |
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 in hexadecimal without a leading "0x". |
"D" or "d" | Represents 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. |
public override int GetHashCode(); |
enumType
value
Exception Type | Condition |
---|---|
ArgumentNullException | enumType or value is null. |
ArgumentException | enumType is not an Enum. -or- value is neither of type enumType nor does it have the same underlying type as enumType. |
enumType
Exception Type | Condition |
---|---|
ArgumentNullException | enumType or value is null. |
ArgumentException | enumType parameter is not an Enum. |
public Type GetType(); |
public TypeCode GetTypeCode(); |
enumType
Exception Type | Condition |
---|---|
ArgumentNullException | enumType is null. |
ArgumentException | enumType is not an Enum. |
enumType
Exception Type | Condition |
---|---|
ArgumentNullException | enumType is null. |
ArgumentException | enumType is not an Enum. |
enumType
value
Exception Type | Condition |
---|---|
ArgumentNullException | enumType or value is null. |
ArgumentException | enumType is not an Enum. -or- The type of value is not an enumType. -or- The type of value is not an underlying type of enumType. |
ExecutionEngineException | value is not type SByte, Int16, Int32, Int64, Byte, UInt16, UInt32, or UInt64. |
protected object MemberwiseClone(); |
enumType
value
Exception Type | Condition |
---|---|
ArgumentNullException | enumType or value is null. |
ArgumentException | enumType is not an Enum. -or- value is either an empty string or only contains white space. -or- value is a name, but not one of the named constants defined for the enumeration. |
This operation is case-sensitive.
enumType
value
ignoreCase
Exception Type | Condition |
---|---|
ArgumentNullException | enumType or value is null. |
ArgumentException | enumType is not an Enum. -or- value is either an empty string ("") or only contains white space. -or- value is a name, but not one of the named constants defined for the enumeration. |
The ignoreCase parameter specifies whether this operation is case-sensitive.
enumType
value
Exception Type | Condition |
---|---|
ArgumentNullException | enumType is null. |
ArgumentException | enumType is not an Enum. |
enumType
value
Exception Type | Condition |
---|---|
ArgumentNullException | enumType is null. |
ArgumentException | enumType is not an Enum. |
enumType
value
Exception Type | Condition |
---|---|
ArgumentNullException | enumType is null. |
ArgumentException | enumType is not an Enum. |
enumType
value
Exception Type | Condition |
---|---|
ArgumentNullException | enumType is null. |
ArgumentException | enumType is not an Enum. |
enumType
value
Exception Type | Condition |
---|---|
ArgumentNullException | enumType is null. |
ArgumentException | enumType is not an Enum. -or- value is not type SByte, Int16, Int32, Int64, Byte, UInt16, UInt32, or UInt64. |
enumType
value
Exception Type | Condition |
---|---|
ArgumentNullException | enumType is null. |
ArgumentException | enumType is not an Enum. |
enumType
value
Exception Type | Condition |
---|---|
ArgumentNullException | enumType is null. |
ArgumentException | enumType is not an Enum. |
enumType
value
Exception Type | Condition |
---|---|
ArgumentNullException | enumType is null. |
ArgumentException | enumType is not an Enum. |
enumType
value
Exception Type | Condition |
---|---|
ArgumentNullException | enumType is null. |
ArgumentException | enumType is not an Enum. |
public override string ToString(); |
For more information about format characters, see the Remarks section of the Enum.Format method. For more information about formatting in general, see the conceptual topic at MSDN: formattingoverview.
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()); } } /* Output. The value of this instance is 'Red'. */
public string ToString( |
provider
format
Exception Type | Condition |
---|---|
FormatException | format contains an invalid specification. |
public string ToString( |
format
provider
Exception Type | Condition |
---|---|
FormatException | format does not contain a valid format specification. |
The provider parameter is reserved; it does not participate in this operation and can be specified as null.