Problem:
Create an enumeration named Month that holds values for the
months of the year, starting with JANUARY equal to 1. (Recall
that an enumeration must be placed within a class but outside
of any method.) Using a GUI interface, prompt the user for a
month integer. Convert the user's entry to a Month value and
display it. Save the project as MonthNamesGUI.
Thats what I have found in google, and i just copy pate it, but I dont know where go to next....
int input, output;
enum month : byte { Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec };
input = Convert.ToInt32(inPutTextBox);
Loading

VulpesRank #55 · 29.2K reputationPosted Dec 13, 2011, 8:57 AM EST
Prime bRank #2,035 · 712 reputationPosted Dec 12, 2011, 4:11 PM EST
Prime bRank #2,035 · 712 reputationPosted Dec 12, 2011, 4:11 PM EST
Sam HobbsRank #107 · 20.5K reputationPosted Dec 12, 2011, 4:30 PM EST
This obviously is for a class assignment. So this is a great way for you to learn how to use the documentation. Note that you need to do the "starting with JANUARY equal to 1" part. Please look at enum (C# Reference). The documentation makes it extremely easy to figure out how to specify that January is 1.
Next, note that inPutTextBox is the TextBox. You need the text that is in the TextBox. Look at the documentation to determine how to do that.
Next, note that month is a type; it is not an instance of something. It is not a place that holds a value; it just describes what a month is. You need to create an instance of a month. Try to figure out how to do that. It will really help you a lot if you can figure it out yourself. When you have an instance of a month, then you can put the converted number (converted using Convert.ToInt32) in that.
I am not sure I understand the part about "display it".
Prime bRank #2,035 · 712 reputationPosted Dec 12, 2011, 4:57 PM EST
Prime bRank #2,035 · 712 reputationPosted Dec 12, 2011, 5:00 PM EST
Prime bRank #2,035 · 712 reputationPosted Dec 13, 2011, 7:37 AM EST
enum month { Jan = 1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec };
private void button1_Click(object sender, EventArgs e)
{
int a = 1;
int b = 2;
int c = 3;
int d = 4;
int o = 5;
int f = 6;
int g = 7;
int h = 8;
int i = 9;
int j = 10;
int k = 11;
int l = 12;
int input;
a = (int)month.Jan;
b = (int)month.Feb;
c = (int)month.Mar;
d = (int)month.Apr;
o = (int)month.May;
f = (int)month.Jun;
g = (int)month.Jul;
h = (int)month.Aug;
i = (int)month.Sep;
j = (int)month.Oct;
k = (int)month.Nov;
l = (int)month.Dec;
input = Convert.ToInt32(inPutTextBox.Text);
my problem: How do I convert the input to the letter that represents the month?
Prime bRank #2,035 · 712 reputationPosted Dec 13, 2011, 9:07 AM EST
VulpesRank #55 · 29.2K reputationPosted Dec 13, 2011, 9:27 AM EST
string monthName = Enum.GetName(typeof(Month), monthNumber);
Jignesh TrivediRank #16 · 50.3K reputationPosted Jan 4, 2012, 10:24 PM EST
try folliwing code.
public static string GetEnumDescription(Enum value)
{
if (value == null)
return string.Empty;
FieldInfo fi = value.GetType().GetField(value.ToString());
DescriptionAttribute[] attributes =
(DescriptionAttribute[])fi.GetCustomAttributes(
typeof(DescriptionAttribute),
false);
if (attributes != null &&
attributes.Length > 0)
return attributes[0].Description;
else
return value.ToString();
}
public enum MonthName
{
[Description("None")]
None =0 ,
[Description("January")]
Jan = 1,
[Description("February")]
Feb,
[Description("March")]
March,
[Description("April")]
April,
[Description("May")]
May,
[Description("June")]
June,
[Description("July")]
July,
[Description("August")]
Aug,
[Description("September")]
Sept,
[Description("October")]
Oct,
[Description("November")]
Nov,
[Description("December")]
Dec
}
And finally
in your application
string monthName = GetEnumDescription(MonthName.Jan);
hope this help.