This documentation is archived and is not being maintained.

EnumConverter Class

Provides a type converter to convert Enum objects to and from various other representations.

For a list of all members of this type, see EnumConverter Members.


[Visual Basic]
Public Class EnumConverter
   Inherits TypeConverter
public class EnumConverter : TypeConverter
public __gc class EnumConverter : public TypeConverter
public class EnumConverter extends TypeConverter

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


This converter can only convert an enumeration object to and from a string. The EnumConverter provides the Comparer property to get an IComparer interface that can be used to sort the values of the enumeration. By default, the enumeration values are sorted in the order they appear in the file.

For more information about type converters, see the TypeConverter base class and Implementing a Type Converter.

Note   You should never create an instance of an EnumConverter. Instead, call the GetConverter method of TypeDescriptor. For more information, see the examples in the TypeConverter base class.

Notes to Inheritors:  If you want to sort the values into a different order, override the Comparer property.


[Visual Basic, C#, C++] The following sample converts a variable of type Enum to a string, and vice versa. The code segment assumes that you have declared an Enum called Servers and that it has the following members, Windows=1, Exchange=2, BizTalk=3

[Visual Basic] 
Dim myServer As Servers = Servers.Exchange
Dim myServerString As string = "BizTalk"
Console.WriteLine(TypeDescriptor.GetConverter(myServer).ConvertTo(myServer, GetType(String))) 

Enum myServer= Servers.Exchange;
string myServerString = "BizTalk";
Console.WriteLine(TypeDescriptor.GetConverter(myServer).ConvertTo(myServer, typeof(string))); 

// Requires public declaration of the following type.
// __value enum Servers {Windows=1, Exchange=2, BizTalk=3};
Servers myServer = Servers::Exchange;
String* myServerString = S"BizTalk";
Console::WriteLine(TypeDescriptor::GetConverter(__box(myServer))->ConvertTo(__box(myServer), __typeof(String)));

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


Namespace: System.ComponentModel

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

EnumConverter Members | System.ComponentModel Namespace