In our development process, we sometimes have the enumeration as the data source to bind some drop-down list, then we need to resolve the enumeration name and value.
First look at the definition of an enumeration:
1 /// <summary>2 ///Database Type3 /// </summary>4 Public enumDatabaseType {5 OLE DB,6 SqLite,7 MssqlServer,8 MYSQL,9 Oracle,Ten Db2, One Other A}
1. Use the given string to match the enumeration type
(DatabaseType) Enum.parse (typeoftrue); The last parameter indicates a case insensitive
2. Gets the string form of the enumeration:
DatabaseType.MySql.ToString ()//MYSQL
3. Get the value of an enumeration
(int) Databasetype.mysql; 3
4. Get enum Types by value
(DatabaseType) 3; Databasetype.mysql
5. Gets the value of an enumeration based on the string form of the given enumeration
Enum.format (typeof(DatabaseType), Enum.parse (typeof"MySql" " D") //3
C # Enumeration related operations--parsing, traversal