1

I have enum :

public enum ConsoleMessageType
{
    Error, Info, BackInfo, Success
}

i want to add values to it in runtime, is this possible?

Yasser
  • 315
  • 2
  • 10
  • 15
  • This has been asked before. Look at http://stackoverflow.com/questions/55375/add-values-to-enum – Rubén López Aug 24 '11 at 10:40
  • @spakinz That is not asking the same question. That is about inheritance, this is about amending the type at runtime. – Adam Houldsworth Aug 24 '11 at 10:42
  • Why would you want to do that? –  Aug 24 '11 at 10:43
  • You can give the enum any value, it just wont have a name. – leppie Aug 24 '11 at 11:05
  • @Yasser Please read this: http://msmvps.com/blogs/jon_skeet/archive/2010/08/29/writing-the-perfect-question.aspx The "Problem statement" part is why i am asking you to state what you wand to achieve –  Aug 25 '11 at 07:26

2 Answers2

1

No. You should use a dictionary for that.

Alejandro Martin
  • 5,691
  • 1
  • 17
  • 21
0

No, this isn't possible.

C# is an strongly-typed language and its nature prevents from supporting such things.

Check this article about expando objects, which is a possible solution for your problem:

Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
  • I dont think it is a good idea to propose a solution to an unknown problem (it might be the wrong one) –  Aug 24 '11 at 10:45
  • 1
    But it's a hint. My answer is _no_, but maybe _expando objects_ would be a **posible** solution (possible, I didn't say **the solution**) – Matías Fidemraizer Aug 24 '11 at 10:57