Linked Questions
61 questions linked to/from String representation of an Enum
23 votes
4 answers
14k views
How to have userfriendly names for enumerations? [duplicate]
I have an enumeration like Enum Complexity { NotSoComplex, LittleComplex, Complex, VeryComplex } And I want to use it in a dropdown list, but don't want to see such Camel names in list (...
5 votes
2 answers
14k views
Enum to String in VB.NET [duplicate]
I have this enumeration Public Enum Applications Unknown = 0 AA = 1 BB = 2 CC = 3 End Enum Private Const CALLING_APP As Applications= Applications.CC CALLING_APP.ToString() is ...
1 vote
0 answers
3k views
override or overload ToString() in an enum [duplicate]
I have an enum like this: public enum MyEnum { people1, people2 } I want to override or overload ToString() method. For example in the following code, variable s becomes "This is people 1". ...
0 votes
1 answer
751 views
Enum of strings in C# [duplicate]
have this class: public static class Command { public const string SET_STB_MEDIA_CTRL = "SET STB MEDIA CTRL "; public static string ECHO = "ECHO"; public static string SET_CHANNEL = "SET ...
1 vote
1 answer
93 views
How to get items of enum in c#? [duplicate]
I want to create a select option in Razor pages from Enum object Description This is my code: <div class="dropdown-box"> <select id="type-select"> @foreach (...
142 votes
21 answers
93k views
How do I have an enum bound combobox with custom string formatting for enum values?
In the post Enum ToString, a method is described to use the custom attribute DescriptionAttribute like this: Enum HowNice { [Description("Really Nice")] ReallyNice, [Description("Kinda Nice")] ...
129 votes
16 answers
131k views
Getting multiple keys of specified value of a generic Dictionary?
It's easy to get the value of a key from a .NET generic Dictionary: Dictionary<int, string> greek = new Dictionary<int, string>(); greek.Add(1, "Alpha"); greek.Add(2, "Beta"); string ...
76 votes
25 answers
8k views
Why is "null" present in C# and Java?
We noticed that lots of bugs in our software developed in C# (or Java) cause a NullReferenceException. Is there a reason why "null" has even been included in the language? After all, if there were ...
30 votes
4 answers
44k views
Public const string?
Is it ok to use a class like this (design / guideline specific)? I'm using MVVM Pattern. public static class Pages { public const string Home = "Home.xaml"; public const string View2 = "View2....
24 votes
3 answers
17k views
C# explicit cast string to enum
I would like to have an explicit cast between from a string to an enum in c# in order to have this : (MyEnum) Enum.Parse(typeof(MyEnum),stringValue) I would like to deport this into an explicit cast ...
19 votes
5 answers
17k views
Behaviour to simulate an enum implementing an interface
Say I have an enum something like: enum OrderStatus { AwaitingAuthorization, InProduction, AwaitingDespatch } I've also created an extension method on my enum to tidy up the displayed ...
19 votes
3 answers
11k views
Use switch statement on type-safe enum pattern
I found a good looking example about implementation enums in a different way. That is called type-safe enum pattern I think. I started using it but I realized that I can not use it in a switch ...
4 votes
4 answers
17k views
Display Text for Enum [duplicate]
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 ...
9 votes
3 answers
24k views
How to somehow define enum type as float or double in c#
It says here that the possible types for an enum are byte, sbyte, short, ushort, int, uint, long, or ulong. What if I need a float or a double to define percentage increments such as 1.5 or 2.5 for ...
21 votes
2 answers
12k views
Anyone know a quick way to get to custom attributes on an enum value?
This is probably best shown with an example. I have an enum with attributes: public enum MyEnum { [CustomInfo("This is a custom attrib")] None = 0, [CustomInfo("This is another attrib")]...