Jump to content

  • Log In with Google      Sign In   
  • Create Account


simple c# question


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 27 February 2012 - 03:47 PM

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.

public enum Months { January=1,Febraury...December};

private void button1_Click(object sender, EventArgs e)
{
int num = Convert.ToInt32(textBox1.Text);
Months month = (Months)num;
this.Text=(month);
}

Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9491

Like
1Likes
Like

Posted 27 February 2012 - 03:55 PM

Did you try Enum.GetName()?

#3 blackbook   Members   -  Reputation: 110

Like
1Likes
Like

Posted 27 February 2012 - 04:35 PM

You can call .ToString() on any object.

http://msdn.microsof...t.tostring.aspx

Here's an enum.ToString() webpage.

http://www.dotnetperls.com/enum-tostring




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS