Total number of items defined in an enum

前端 未结 10 730
你的背包
你的背包 2020-11-30 18:36

How can I get the number of items defined in an enum?

10条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 19:31

    You can use Enum.GetNames to return an IEnumerable of values in your enum and then .Count the resulting IEnumerable.

    GetNames produces much the same result as GetValues but is faster.

提交回复
热议问题