How can I have AC # enum that if I select the string then it gives a different string, such as java In this it can be done by
public enum sample {some, other, things; Public string toString () {switch (it) {some cases: return "you choose something"; Default: Break; >> console.witLine (sample.some) will be output: you select something < / Pre> I just want to return a different string to my EMAN when I try to call them.
This is not possible for my knowledge. However, you can type an extension method that gets some other string:
public static class EnumExtensions {public static string toSampleString (this sample enum enum) {switch (enum) {case SampleEnum .Value1: return "Foo"; For example SampleEnum :
Now, just this new Call ToSampleString mySampleEnum.ToSampleString (); If you are unfamiliar with the extension methods in C # , read more. Another option is to use the description attribute described above each enum value.
No comments:
Post a Comment