mscorlib(4.0.0.0) API with additions
System.Enum Class Reference

Provides the base class for enumerations. More...

Inheritance diagram for System.Enum:
[legend]
Collaboration diagram for System.Enum:
[legend]

Public Member Functions

override bool Equals (object obj)
 Returns a value indicating whether this instance is equal to a specified object. More...
 
unsafe override int GetHashCode ()
 Returns the hash code for the value of this instance. More...
 
override string ToString ()
 Converts the value of this instance to its equivalent string representation. More...
 
string ToString (string format, IFormatProvider provider)
 This method overload is obsolete; use M:System.Enum.ToString(System.String). More...
 
int CompareTo (object target)
 Compares this instance to a specified object and returns an indication of their relative values. More...
 
string ToString (string format)
 Converts the value of this instance to its equivalent string representation using the specified format. More...
 
string ToString (IFormatProvider provider)
 This method overload is obsolete; use M:System.Enum.ToString. More...
 
bool HasFlag (Enum flag)
 Determines whether one or more bit fields are set in the current instance. More...
 
TypeCode GetTypeCode ()
 Returns the type code of the underlying type of this enumeration member. More...
 

Static Public Member Functions

static bool TryParse< TEnum > (string value, out TEnum result)
 Converts the string representation of the name or numeric value of one or more enumerated constants to an equivalent enumerated object. The return value indicates whether the conversion succeeded. More...
 
static bool TryParse< TEnum > (string value, bool ignoreCase, out TEnum result)
 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. The return value indicates whether the conversion succeeded. More...
 
static object 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. More...
 
static object 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-insensitive. More...
 
static Type GetUnderlyingType (Type enumType)
 Returns the underlying type of the specified enumeration. More...
 
static Array GetValues (Type enumType)
 Retrieves an array of the values of the constants in a specified enumeration. More...
 
static string GetName (Type enumType, object value)
 Retrieves the name of the constant in the specified enumeration that has the specified value. More...
 
static string [] GetNames (Type enumType)
 Retrieves an array of the names of the constants in a specified enumeration. More...
 
static object ToObject (Type enumType, object value)
 Converts the specified object with an integer value to an enumeration member. More...
 
static bool IsDefined (Type enumType, object value)
 Returns an indication whether a constant with a specified value exists in a specified enumeration. More...
 
static string Format (Type enumType, object value, string format)
 Converts the specified value of a specified enumerated type to its equivalent string representation according to the specified format. More...
 
static object ToObject (Type enumType, sbyte value)
 Converts the specified 8-bit signed integer value to an enumeration member. More...
 
static object ToObject (Type enumType, short value)
 Converts the specified 16-bit signed integer to an enumeration member. More...
 
static object ToObject (Type enumType, int value)
 Converts the specified 32-bit signed integer to an enumeration member. More...
 
static object ToObject (Type enumType, byte value)
 Converts the specified 8-bit unsigned integer to an enumeration member. More...
 
static object ToObject (Type enumType, ushort value)
 Converts the specified 16-bit unsigned integer value to an enumeration member. More...
 
static object ToObject (Type enumType, uint value)
 Converts the specified 32-bit unsigned integer value to an enumeration member. More...
 
static object ToObject (Type enumType, long value)
 Converts the specified 64-bit signed integer to an enumeration member. More...
 
static object ToObject (Type enumType, ulong value)
 Converts the specified 64-bit unsigned integer value to an enumeration member. More...
 

Protected Member Functions

 Enum ()
 Initializes a new instance of the T:System.Enum class. More...
 

Detailed Description

Provides the base class for enumerations.

Definition at line 14 of file Enum.cs.

Constructor & Destructor Documentation

◆ Enum()

System.Enum.Enum ( )
protected

Initializes a new instance of the T:System.Enum class.

Definition at line 1336 of file Enum.cs.

Member Function Documentation

◆ CompareTo()

int System.Enum.CompareTo ( object  target)

Compares this instance to a specified object and returns an indication of their relative values.

Parameters
targetAn object to compare, or null.
Returns
A signed number that indicates the relative values of this instance and target .Value Meaning Less than zero The value of this instance is less than the value of target . Zero The value of this instance is equal to the value of target . Greater than zero The value of this instance is greater than the value of target .-or- target is null.
Exceptions
T:System.ArgumentExceptiontarget and this instance are not the same type.
T:System.InvalidOperationExceptionThis instance is not type T:System.SByte, T:System.Int16, T:System.Int32, T:System.Int64, T:System.Byte, T:System.UInt16, T:System.UInt32, or T:System.UInt64.

Definition at line 793 of file Enum.cs.

◆ Equals()

override bool System.Enum.Equals ( object  obj)

Returns a value indicating whether this instance is equal to a specified object.

Parameters
objAn object to compare with this instance, or null.
Returns
true if obj is an enumeration value of the same type and with the same underlying value as this instance; otherwise, false.

◆ Format()

static string System.Enum.Format ( Type  enumType,
object  value,
string  format 
)
static

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

Parameters
enumTypeThe enumeration type of the value to convert.
valueThe value to convert.
formatThe output format to use.
Returns
A string representation of value .
Exceptions
T:System.ArgumentNullExceptionThe enumType , value , or format parameter is null.
T:System.ArgumentExceptionThe enumType parameter is not an T:System.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 .
T:System.FormatExceptionThe format parameter contains an invalid value.
T:System.InvalidOperationExceptionformat equals "X", but the enumeration type is unknown.

Definition at line 598 of file Enum.cs.

◆ GetHashCode()

unsafe override int System.Enum.GetHashCode ( )

Returns the hash code for the value of this instance.

Returns
A 32-bit signed integer hash code.

Definition at line 722 of file Enum.cs.

◆ GetName()

static string System.Enum.GetName ( Type  enumType,
object  value 
)
static

Retrieves the name of the constant in the specified enumeration that has the specified value.

Parameters
enumTypeAn enumeration type.
valueThe value of a particular enumerated constant in terms of its underlying type.
Returns
A string containing the name of the enumerated constant in enumType whose value is value ; or null if no such constant is found.
Exceptions
T:System.ArgumentNullExceptionenumType or value is null.
T:System.ArgumentExceptionenumType is not an T:System.Enum.-or- value is neither of type enumType nor does it have the same underlying type as enumType .

Definition at line 482 of file Enum.cs.

◆ GetNames()

static string [] System.Enum.GetNames ( Type  enumType)
static

Retrieves an array of the names of the constants in a specified enumeration.

Parameters
enumTypeAn enumeration type.
Returns
A string array of the names of the constants in enumType .
Exceptions
T:System.ArgumentNullExceptionenumType is null.
T:System.ArgumentExceptionenumType parameter is not an T:System.Enum.

Definition at line 500 of file Enum.cs.

◆ GetTypeCode()

TypeCode System.Enum.GetTypeCode ( )

Returns the type code of the underlying type of this enumeration member.

Returns
The type code of the underlying type of this instance.
Exceptions
T:System.InvalidOperationExceptionThe enumeration type is unknown.

Implements System.IConvertible.

Definition at line 879 of file Enum.cs.

◆ GetUnderlyingType()

static Type System.Enum.GetUnderlyingType ( Type  enumType)
static

Returns the underlying type of the specified enumeration.

Parameters
enumTypeThe enumeration whose underlying type will be retrieved.
Returns
The underlying type of enumType .
Exceptions
T:System.ArgumentNullExceptionenumType is null.
T:System.ArgumentExceptionenumType is not an T:System.Enum.

Definition at line 436 of file Enum.cs.

◆ GetValues()

static Array System.Enum.GetValues ( Type  enumType)
static

Retrieves an array of the values of the constants in a specified enumeration.

Parameters
enumTypeAn enumeration type.
Returns
An array that contains the values of the constants in enumType .
Exceptions
T:System.ArgumentNullExceptionenumType is null.
T:System.ArgumentExceptionenumType is not an T:System.Enum.
T:System.InvalidOperationExceptionThe method is invoked by reflection in a reflection-only context, -or-
    <paramref name="enumType" /> is a type from an assembly loaded in a reflection-only context.</exception> 

Definition at line 457 of file Enum.cs.

◆ HasFlag()

bool System.Enum.HasFlag ( Enum  flag)

Determines whether one or more bit fields are set in the current instance.

Parameters
flagAn enumeration value.
Returns
true if the bit field or bit fields that are set in flag are also set in the current instance; otherwise, false.
Exceptions
T:System.ArgumentExceptionflag is a different type than the current instance.

Definition at line 863 of file Enum.cs.

◆ IsDefined()

static bool System.Enum.IsDefined ( Type  enumType,
object  value 
)
static

Returns an indication whether a constant with a specified value exists in a specified enumeration.

Parameters
enumTypeAn enumeration type.
valueThe value or name of a constant in enumType .
Returns
true if a constant in enumType has a value equal to value ; otherwise, false.
Exceptions
T:System.ArgumentNullExceptionenumType or value is null.
T:System.ArgumentExceptionenumType is not an Enum.-or- The type of value is an enumeration, but it is not an enumeration of type enumType .-or- The type of value is not an underlying type of enumType .
T:System.InvalidOperationExceptionvalue is not type T:System.SByte, T:System.Int16, T:System.Int32, T:System.Int64, T:System.Byte, T:System.UInt16, T:System.UInt32, or T:System.UInt64, or T:System.String.

Definition at line 577 of file Enum.cs.

◆ Parse() [1/2]

static object System.Enum.Parse ( Type  enumType,
string  value 
)
static

Converts the string representation of the name or numeric value of one or more enumerated constants to an equivalent enumerated object.

Parameters
enumTypeAn enumeration type.
valueA string containing the name or value to convert.
Returns
An object of type enumType whose value is represented by value .
Exceptions
T:System.ArgumentNullExceptionenumType or value is null.
T:System.ArgumentExceptionenumType is not an T:System.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.
T:System.OverflowExceptionvalue is outside the range of the underlying type of enumType .

Definition at line 298 of file Enum.cs.

◆ Parse() [2/2]

static object System.Enum.Parse ( Type  enumType,
string  value,
bool  ignoreCase 
)
static

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-insensitive.

Parameters
enumTypeAn enumeration type.
valueA string containing the name or value to convert.
ignoreCasetrue to ignore case; false to regard case.
Returns
An object of type enumType whose value is represented by value .
Exceptions
T:System.ArgumentNullExceptionenumType or value is null.
T:System.ArgumentExceptionenumType is not an T:System.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.
T:System.OverflowExceptionvalue is outside the range of the underlying type of enumType .

Definition at line 319 of file Enum.cs.

◆ ToObject() [1/9]

static object System.Enum.ToObject ( Type  enumType,
object  value 
)
static

Converts the specified object with an integer value to an enumeration member.

Parameters
enumTypeThe enumeration type to return.
valueThe value convert to an enumeration member.
Returns
An enumeration object whose value is value .
Exceptions
T:System.ArgumentNullExceptionenumType or value is null.
T:System.ArgumentExceptionenumType is not an T:System.Enum.-or- value is not type T:System.SByte, T:System.Int16, T:System.Int32, T:System.Int64, T:System.Byte, T:System.UInt16, T:System.UInt32, or T:System.UInt64.

Definition at line 525 of file Enum.cs.

◆ ToObject() [2/9]

static object System.Enum.ToObject ( Type  enumType,
sbyte  value 
)
static

Converts the specified 8-bit signed integer value to an enumeration member.

Parameters
enumTypeThe enumeration type to return.
valueThe value to convert to an enumeration member.
Returns
An instance of the enumeration set to value .
Exceptions
T:System.ArgumentNullExceptionenumType is null.
T:System.ArgumentExceptionenumType is not an T:System.Enum.

Definition at line 1079 of file Enum.cs.

◆ ToObject() [3/9]

static object System.Enum.ToObject ( Type  enumType,
short  value 
)
static

Converts the specified 16-bit signed integer to an enumeration member.

Parameters
enumTypeThe enumeration type to return.
valueThe value to convert to an enumeration member.
Returns
An instance of the enumeration set to value .
Exceptions
T:System.ArgumentNullExceptionenumType is null.
T:System.ArgumentExceptionenumType is not an T:System.Enum.

Definition at line 1107 of file Enum.cs.

◆ ToObject() [4/9]

static object System.Enum.ToObject ( Type  enumType,
int  value 
)
static

Converts the specified 32-bit signed integer to an enumeration member.

Parameters
enumTypeThe enumeration type to return.
valueThe value to convert to an enumeration member.
Returns
An instance of the enumeration set to value .
Exceptions
T:System.ArgumentNullExceptionenumType is null.
T:System.ArgumentExceptionenumType is not an T:System.Enum.

Definition at line 1135 of file Enum.cs.

◆ ToObject() [5/9]

static object System.Enum.ToObject ( Type  enumType,
byte  value 
)
static

Converts the specified 8-bit unsigned integer to an enumeration member.

Parameters
enumTypeThe enumeration type to return.
valueThe value to convert to an enumeration member.
Returns
An instance of the enumeration set to value .
Exceptions
T:System.ArgumentNullExceptionenumType is null.
T:System.ArgumentExceptionenumType is not an T:System.Enum.

Definition at line 1163 of file Enum.cs.

◆ ToObject() [6/9]

static object System.Enum.ToObject ( Type  enumType,
ushort  value 
)
static

Converts the specified 16-bit unsigned integer value to an enumeration member.

Parameters
enumTypeThe enumeration type to return.
valueThe value to convert to an enumeration member.
Returns
An instance of the enumeration set to value .
Exceptions
T:System.ArgumentNullExceptionenumType is null.
T:System.ArgumentExceptionenumType is not an T:System.Enum.

Definition at line 1192 of file Enum.cs.

◆ ToObject() [7/9]

static object System.Enum.ToObject ( Type  enumType,
uint  value 
)
static

Converts the specified 32-bit unsigned integer value to an enumeration member.

Parameters
enumTypeThe enumeration type to return.
valueThe value to convert to an enumeration member.
Returns
An instance of the enumeration set to value .
Exceptions
T:System.ArgumentNullExceptionenumType is null.
T:System.ArgumentExceptionenumType is not an T:System.Enum.

Definition at line 1221 of file Enum.cs.

◆ ToObject() [8/9]

static object System.Enum.ToObject ( Type  enumType,
long  value 
)
static

Converts the specified 64-bit signed integer to an enumeration member.

Parameters
enumTypeThe enumeration type to return.
valueThe value to convert to an enumeration member.
Returns
An instance of the enumeration set to value .
Exceptions
T:System.ArgumentNullExceptionenumType is null.
T:System.ArgumentExceptionenumType is not an T:System.Enum.

Definition at line 1249 of file Enum.cs.

◆ ToObject() [9/9]

static object System.Enum.ToObject ( Type  enumType,
ulong  value 
)
static

Converts the specified 64-bit unsigned integer value to an enumeration member.

Parameters
enumTypeThe enumeration type to return.
valueThe value to convert to an enumeration member.
Returns
An instance of the enumeration set to value .
Exceptions
T:System.ArgumentNullExceptionenumType is null.
T:System.ArgumentExceptionenumType is not an T:System.Enum.

Definition at line 1278 of file Enum.cs.

◆ ToString() [1/4]

override string System.Enum.ToString ( )

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

Returns
The string representation of the value of this instance.

Definition at line 765 of file Enum.cs.

◆ ToString() [2/4]

string System.Enum.ToString ( string  format,
IFormatProvider  provider 
)

This method overload is obsolete; use M:System.Enum.ToString(System.String).

Parameters
formatA format specification.
provider(Obsolete.)
Returns
The string representation of the value of this instance as specified by format .
Exceptions
T:System.FormatExceptionformat does not contain a valid format specification.
T:System.InvalidOperationExceptionformat equals "X", but the enumeration type is unknown.

Implements System.IFormattable.

Definition at line 779 of file Enum.cs.

◆ ToString() [3/4]

string System.Enum.ToString ( string  format)

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

Parameters
formatA format string.
Returns
The string representation of the value of this instance as specified by format .
Exceptions
T:System.FormatExceptionformat contains an invalid specification.
T:System.InvalidOperationExceptionformat equals "X", but the enumeration type is unknown.

Definition at line 821 of file Enum.cs.

◆ ToString() [4/4]

string System.Enum.ToString ( IFormatProvider  provider)

This method overload is obsolete; use M:System.Enum.ToString.

Parameters
provider(obsolete)
Returns
The string representation of the value of this instance.

Implements System.IConvertible.

Definition at line 850 of file Enum.cs.

◆ TryParse< TEnum >() [1/2]

static bool System.Enum.TryParse< TEnum > ( string  value,
out TEnum  result 
)
static

Converts the string representation of the name or numeric value of one or more enumerated constants to an equivalent enumerated object. The return value indicates whether the conversion succeeded.

Parameters
valueThe string representation of the enumeration name or underlying value to convert.
resultWhen this method returns, result contains an object of type TEnum whose value is represented by value if the parse operation succeeds. If the parse operation fails, result contains the default value of the underlying type of TEnum . Note that this value need not be a member of the TEnum enumeration. This parameter is passed uninitialized.
Template Parameters
TEnumThe enumeration type to which to convert value .
Returns
true if the value parameter was converted successfully; otherwise, false.
Exceptions
T:System.ArgumentExceptionTEnum is not an enumeration type.
Type Constraints
TEnum :struct 

Definition at line 255 of file Enum.cs.

◆ TryParse< TEnum >() [2/2]

static bool System.Enum.TryParse< TEnum > ( string  value,
bool  ignoreCase,
out TEnum  result 
)
static

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. The return value indicates whether the conversion succeeded.

Parameters
valueThe string representation of the enumeration name or underlying value to convert.
ignoreCasetrue to ignore case; false to consider case.
resultWhen this method returns, result contains an object of type TEnum whose value is represented by value if the parse operation succeeds. If the parse operation fails, result contains the default value of the underlying type of TEnum . Note that this value need not be a member of the TEnum enumeration. This parameter is passed uninitialized.
Template Parameters
TEnumThe enumeration type to which to convert value .
Returns
true if the value parameter was converted successfully; otherwise, false.
Exceptions
T:System.ArgumentExceptionTEnum is not an enumeration type.
Type Constraints
TEnum :struct 

Definition at line 271 of file Enum.cs.


The documentation for this class was generated from the following file: