0

I have enum

enum TestEnum : byte
    {
        one = 1,
        two = 2
    }

I am getting name of enum by

var x = Enum.GetName(typeof(TestEnum), TestEnum.one);

Now here i am getting x = 'one'

I want to get 'TTT' (TTT is any custom name)by setting some attribute on Enum. So that when i call

var x = Enum.GetName(typeof(TestEnum), TestEnum.one);

I can get x = 'TTT'

I tried with 'DisplayNameAttribute' but not getting.

Hemant Malpote
  • 891
  • 13
  • 28
  • 4
    "I tried with 'DisplayNameAttribute' but not getting." - so show what you tried. (You'd need to write code to retrieve the attribute for the right value, of course...) – Jon Skeet Aug 06 '15 at 13:22
  • You can try this: http://stackoverflow.com/questions/630803/associating-enums-with-strings-in-c-sharp - the first one is no good, but some of latters are going to fit nicely – Paweł Mach Aug 06 '15 at 13:24
  • this is what you are looking for: http://stackoverflow.com/questions/1799370/getting-attributes-of-enums-value – David Leitner Aug 06 '15 at 13:27
  • @Jone Skeet : Can show me how it use with DisplayName – Hemant Malpote Aug 06 '15 at 13:27

0 Answers0