列舉值檢查 typeof(enumType).IsEnumDefined(intValue)

  • 278
  • 0
  • C#
  • 2026-11-24

typeof(enumType).IsEnumDefined(intValue)

API 收到未定義的列舉值,例如 (MyEnum)0,不會自動報錯,程式仍會照常執行。要用 typeof(MyEnum).IsEnumDefined(value) 自己檢查。

完整文章與更新版本已搬到 jakeuj.com:列舉值檢查 typeof(enumType).IsEnumDefined(intValue)

PS5

本部落格已搬到 jakeuj.com,文章在新站持續更新。