• Advertisement
Sign in to follow this  

simple c# question

This topic is 2153 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to convert a enum type to a string.I am getting an error with the following line: label2.Text = month.
here is the code I am working with.

[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]public enum Months { January=1,Febraury...December};[/color][/size][/font][/color][/size][/font][/color][/size][/font]

[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]private[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] [/size][/font][/size][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]void[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] button1_Click([/size][/font][/size][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]object[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] sender, [/size][/font][/size][/font][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]EventArgs[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] e)[/size][/font][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/size][/font][/size][/font]
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]int[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] num = [/size][/font][/size][/font][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]Convert[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"].ToInt32(textBox1.Text);[/size][/font][/size][/font]
[font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]Months[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] month = ([/size][/font][/size][/font][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]Months[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"])num;[/size][/font][/size][/font]
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]this[/color][/size][/font][/color][/size][/font][/color][/size][/font][font="Consolas"][size="2"][font="Consolas"][size="2"].Text=(month);[/size][/font][/size][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/size][/font][/size][/font]

Share this post


Link to post
Share on other sites
Advertisement
Did you try [url=http://msdn.microsoft.com/en-us/library/system.enum.getname(v=vs.100).aspx]Enum.GetName()[/url]?

Share this post


Link to post
Share on other sites
You can call .ToString() on any object.

[url="http://msdn.microsoft.com/en-us/library/system.object.tostring.aspx"]http://msdn.microsof...t.tostring.aspx[/url]

Here's an enum.ToString() webpage.

[url="http://www.dotnetperls.com/enum-tostring"]http://www.dotnetperls.com/enum-tostring[/url]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement