0

I have enum :

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

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

5
  • This has been asked before. Look at stackoverflow.com/questions/55375/add-values-to-enum Commented Aug 24, 2011 at 10:40
  • @spakinz That is not asking the same question. That is about inheritance, this is about amending the type at runtime. Commented Aug 24, 2011 at 10:42
  • Why would you want to do that? Commented Aug 24, 2011 at 10:43
  • You can give the enum any value, it just wont have a name. Commented Aug 24, 2011 at 11:05
  • @Yasser Please read this: msmvps.com/blogs/jon_skeet/archive/2010/08/29/… The "Problem statement" part is why i am asking you to state what you wand to achieve Commented Aug 25, 2011 at 7:26

2 Answers 2

1

No. You should use a dictionary for that.

Sign up to request clarification or add additional context in comments.

Comments

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:

2 Comments

I dont think it is a good idea to propose a solution to an unknown problem (it might be the wrong one)
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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.