How can I get the number of enums as a constant?

Evorlor

From Total number of items defined in an enum, I see I can get the number of enums by using:

Enum.GetNames(typeof(Item.Type)).Length;

Works great!

But, I need this number as a constant number, so that I can use it in Unity's [Range(int, int)] feature.

private const int constEnumCount = Enum.GetNames(typeof(Item.Type)).Length;

The above does not work, because the enum count is not a constant number, so I cannot assign it to a constant variable.

How can I get the number of enums as a constant?

Almo

It's not possible to get the number of enums as a const. Enum.GetNames uses reflection to get these things, and that's inherently a runtime operation. Therefore, it can't be known at compile time, which is a requirement for being const.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How can i get the number without repetition?

分類Dev

How can I get the line number which threw exception?

分類Dev

How can I get the number of characters from an input string?

分類Dev

How can I get issues since any number?

分類Dev

How can I get issues since any number?

分類Dev

How can I get the PORT number when using Nginx + Tornado?

分類Dev

How can I check for the existance of an enum value in an array of Enums?

分類Dev

Can enums have variable number of parameters?

分類Dev

How can i 'get' the number i have entered into the label widget into a variable?

分類Dev

If I know the PID number of a process, how can I get its name?

分類Dev

How can I use a constant value as a flowtype literal?

分類Dev

how can i get the number of products in each countries using my django models

分類Dev

How can I get the number of columns and rows from 2D list

分類Dev

How can I get bookmarks page number in a PDF file with Apache PdfBox?

分類Dev

How can I get the row-ID or row-number in a ListTile?

分類Dev

How i can get the number of followers from a Instagram profile using ASPX.NET (C#)

分類Dev

How can I get the number of logins each day in the current month using awk?

分類Dev

How can I get the last line number of unique commands when grepping my history file?

分類Dev

How can i get sectionid

分類Dev

how can i combine href with id number

分類Dev

How can I do this, but with a changeable number of dice?

分類Dev

How can I search for the number in the array?

分類Dev

how can I get nth digit in a BigInteger?

分類Dev

How can I get Mockito working in androidTest

分類Dev

How can I get a unique thread identifier?

分類Dev

How can I get a renderer in a-frame

分類Dev

How can I get last segment of the string?

分類Dev

How can I get array of UIStoryboard in Swift?

分類Dev

How can i get uri segment in routes?

Related 関連記事

  1. 1

    How can i get the number without repetition?

  2. 2

    How can I get the line number which threw exception?

  3. 3

    How can I get the number of characters from an input string?

  4. 4

    How can I get issues since any number?

  5. 5

    How can I get issues since any number?

  6. 6

    How can I get the PORT number when using Nginx + Tornado?

  7. 7

    How can I check for the existance of an enum value in an array of Enums?

  8. 8

    Can enums have variable number of parameters?

  9. 9

    How can i 'get' the number i have entered into the label widget into a variable?

  10. 10

    If I know the PID number of a process, how can I get its name?

  11. 11

    How can I use a constant value as a flowtype literal?

  12. 12

    how can i get the number of products in each countries using my django models

  13. 13

    How can I get the number of columns and rows from 2D list

  14. 14

    How can I get bookmarks page number in a PDF file with Apache PdfBox?

  15. 15

    How can I get the row-ID or row-number in a ListTile?

  16. 16

    How i can get the number of followers from a Instagram profile using ASPX.NET (C#)

  17. 17

    How can I get the number of logins each day in the current month using awk?

  18. 18

    How can I get the last line number of unique commands when grepping my history file?

  19. 19

    How can i get sectionid

  20. 20

    how can i combine href with id number

  21. 21

    How can I do this, but with a changeable number of dice?

  22. 22

    How can I search for the number in the array?

  23. 23

    how can I get nth digit in a BigInteger?

  24. 24

    How can I get Mockito working in androidTest

  25. 25

    How can I get a unique thread identifier?

  26. 26

    How can I get a renderer in a-frame

  27. 27

    How can I get last segment of the string?

  28. 28

    How can I get array of UIStoryboard in Swift?

  29. 29

    How can i get uri segment in routes?

ホットタグ

アーカイブ