Difference between Enum.GetValues and Enum.GetNames

后端 未结 3 912
故里飘歌
故里飘歌 2020-12-16 13:48

I see the Enum.GetValues returns base Array type and Enum.GetNames returns a string array. But I don\'t understand how th

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-16 14:40

    Think of enumerations as Name/Value pairs.

    enum SignMagnitude { Negative = -1, Zero = 0, Positive = 1 };
    

    In the example above, GetNames() will return a string array containing the items "Negative", "Zero", and "Positive." GetValues() will return an array of SignMagnitude containing SignMagnitude.Negative, SignMagnitude.Zero and SignMagnitude.One.


    There is an example of binding Enum names to a dropdown in a DataGridView here: Create drop down list options from enum in a DataGridView

提交回复
热议问题