How to TryParse for Enum value?

前端 未结 14 968
终归单人心
终归单人心 2020-11-29 00:22

I want to write a function which can validate a given value (passed as a string) against possible values of an enum. In the case of a match, it should return th

14条回答
  •  一向
    一向 (楼主)
    2020-11-29 00:30

    Is caching a dynamically generated function/dictionary permissable?

    Because you don't (appear to) know the type of the enum ahead of time, the first execution could generate something subsequent executions could take advantage of.

    You could even cache the result of Enum.GetNames()

    Are you trying to optimize for CPU or Memory? Do you really need to?

提交回复
热议问题