enums

Display Text for Enum [duplicate]

微笑、不失礼 提交于 2020-07-30 02:40:10
问题 This question already has answers here : String to enum conversion in C# (8 answers) C# using numbers in an enum (7 answers) Closed 7 years ago . HI I have the following enum public enum Priority : byte { A=1, B+ = 2, B=4, C=8, D=16, E=32 } I want to add B+ in the enum but it is giving me error 回答1: You can add user friendly description for enum like below : enum MyEnum { [Description("This is black")] Black, [Description("This is white")] White } Ref. Link : How to have userfriendly names

Enum is defined but not found in the class

十年热恋 提交于 2020-07-23 06:08:16
问题 The solution consists of three classes: the SongGenre, the Song and the Library (+ Program). I am just following the instructions so most of coding comes from my lectures and the book and not much of the experience. It is what what you see and I am not really proud of it. Pointers are really appreciated. The main one is why the enum values can not be seen in another classes? This code has been fixed (see comments). namespace SongLibrary { [Flags] enum SongGenre { Unclassified = 0, Pop = 0b1,

Enum is defined but not found in the class

不羁岁月 提交于 2020-07-23 06:07:22
问题 The solution consists of three classes: the SongGenre, the Song and the Library (+ Program). I am just following the instructions so most of coding comes from my lectures and the book and not much of the experience. It is what what you see and I am not really proud of it. Pointers are really appreciated. The main one is why the enum values can not be seen in another classes? This code has been fixed (see comments). namespace SongLibrary { [Flags] enum SongGenre { Unclassified = 0, Pop = 0b1,

Enum is defined but not found in the class

末鹿安然 提交于 2020-07-23 06:06:47
问题 The solution consists of three classes: the SongGenre, the Song and the Library (+ Program). I am just following the instructions so most of coding comes from my lectures and the book and not much of the experience. It is what what you see and I am not really proud of it. Pointers are really appreciated. The main one is why the enum values can not be seen in another classes? This code has been fixed (see comments). namespace SongLibrary { [Flags] enum SongGenre { Unclassified = 0, Pop = 0b1,

Convert Objective-C enum to Swift String

两盒软妹~` 提交于 2020-07-23 03:13:08
问题 I'm trying to convert iOS error codes to String in Swift 2 (XCode 7.2). But converting to String returns the type name instead of the value name for system enums. This is what I'm trying: import CoreLocation import EventKit let clError = CLError.LocationUnknown let clErrorString = "\(clError)" // EXPECTED: 'LocationUnknown'. OBTAINED: 'CLError' let ekError = EKErrorCode.CalendarIsImmutable let ekErrorString = "\(ekError)" // EXPECTED: 'CalendarIsImmutable'. OBTAINED: 'EKErrorCode' But with

Convert Objective-C enum to Swift String

大兔子大兔子 提交于 2020-07-23 03:11:11
问题 I'm trying to convert iOS error codes to String in Swift 2 (XCode 7.2). But converting to String returns the type name instead of the value name for system enums. This is what I'm trying: import CoreLocation import EventKit let clError = CLError.LocationUnknown let clErrorString = "\(clError)" // EXPECTED: 'LocationUnknown'. OBTAINED: 'CLError' let ekError = EKErrorCode.CalendarIsImmutable let ekErrorString = "\(ekError)" // EXPECTED: 'CalendarIsImmutable'. OBTAINED: 'EKErrorCode' But with

Get name of Enum instance [closed]

旧巷老猫 提交于 2020-07-21 06:07:53
问题 Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . Improve this question Say I have this enum: public enum MyEnum{ ValueOne = 1, ValueTwo = 2, ValueThree = 3 } And then this field/variable: public MyEnum myEnumInstance = MyEnum.ValueTwo; I need to get the name of myEnumInstance via reflection from another class . I tried:

Get name of Enum instance [closed]

烈酒焚心 提交于 2020-07-21 06:07:39
问题 Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . Improve this question Say I have this enum: public enum MyEnum{ ValueOne = 1, ValueTwo = 2, ValueThree = 3 } And then this field/variable: public MyEnum myEnumInstance = MyEnum.ValueTwo; I need to get the name of myEnumInstance via reflection from another class . I tried:

Why isn't an enum checked by the C compiler?

家住魔仙堡 提交于 2020-07-20 07:33:50
问题 The following text is an excerpt from C Programming Language, 2nd Edition , written by the creator of the C language (so I presume it is correct): Although variables of enum types may be declared, compilers need not check that what you store in such a variable is a valid value for the enumeration. I have some doubts: For what cases in the C language doesn't the compiler check the value of an enum ? enum constants are not checked for some reason. Why not? What are the reasons? Since enum is

Why isn't an enum checked by the C compiler?

感情迁移 提交于 2020-07-20 07:32:32
问题 The following text is an excerpt from C Programming Language, 2nd Edition , written by the creator of the C language (so I presume it is correct): Although variables of enum types may be declared, compilers need not check that what you store in such a variable is a valid value for the enumeration. I have some doubts: For what cases in the C language doesn't the compiler check the value of an enum ? enum constants are not checked for some reason. Why not? What are the reasons? Since enum is