VB.net: parse to enum, by value

Seite 1 von 1 - Forum: Coding Stuff auf overclockers.at

URL: https://www.overclockers.at/coding-stuff/vb-net-parse-to-enum-by-value_246696/page_1 - zur Vollversion wechseln!


wergor schrieb am 22.07.2016 um 19:19

ich habe in meinem code z.b. folgendes enum:

Code: VBNET
Enum onewire_sensor_family_t
	DS18S20 = &H10          'sensor is a DS1820 Or DS18S20
	DS18B20 = &H28          'sensor is a DS18B20
	DS1822 = &H22           'sensor is a DS1822
End Enum

parsing by name funktioniert problemlos:
Code: VBNET
Dim family as String = "DS18S20"
[Enum].TryParse(Of Focuser.onewire_sensor_family_t)(family, returnValue)
aber parsing by value funktioniert nicht - wenn family 0 ist bekomme ich 0 zurück, bei 1 bekomme ich 1 etc.
weis jemand woran das liegt bzw wie es richtig gemacht wird?


wergor schrieb am 24.07.2016 um 17:21

ich habe die lösung gefunden - man muss erst mit

Code: VBNET
[Enum].IsDefined
checken ob der value im enum enthalten ist.




overclockers.at v4.thecommunity
© all rights reserved by overclockers.at 2000-2025