blog.pagesd.info // Archives // Traductions

Convertir un type String en Enum

2005-10-20 #code-snippets,#c-sharp

enum EngineType {
  unknow,
  access,
  db2,
  mysql,
  odbc,
  oledb,
  oracle,
  postgre,
  sqlserver
}
string cnxTypeString = "mysql";
EngineType cnxTypeEngine = EngineType.unknow;
if (Enum.IsDefined(typeof(EngineType), cnxTypeString)) {
  cnxTypeEngine = (EngineType) Enum.Parse(typeof(EngineType), cnxTypeString, true);
}