contacthanu

Hi

I have month numbers like 1,2,3,4,5,6.........12. I want to get the month name by passing these values. Is there any function to get the name directly without writing any case statemnet.

For example:

Private string GetMonthName(int month)

{

Here i need the function to get the month name

}

Regards

Hanu




Re: Visual C# Express Edition month name converting problem

johan idstam

return DateTimeFormatInfo.CurrentInfo.MonthNames[month -1];



/johan/




Re: Visual C# Express Edition month name converting problem

ECasabuena

I think the best way to do that is to use an enumerated type( enum) here's an example:

public enum Month : int
{
January = 1,
February = 2,
March = 3,
April = 4,
May = 5,
June = 6,
July = 7,
.
.
.
December = 12,
}







Re: Visual C# Express Edition month name converting problem

ECasabuena

I think the solution to your problem is by using an enumerated type known as enum
here is an example program:

1. create a class

using System;
using System.Collections.Generic;
using System.Text;

namespace Enum
{
public class Sample
{
//private field
private Months month = Months.January; // set the default value;

//public field
public Months MonthValue
{
get { return month; }
set { month = value; }
}
}

public enum Months : int
{
January = 1,
February = 2,
March = 3,
April = 4,
May = 5,
June = 6,
July = 7,
August = 8,
September = 9,
October = 10,
November = 11,
December = 12,
}
}

2. Main Program

using System;
using System.Collections.Generic;
using System.Text;

namespace Enum
{
class Program
{
static void Main(string[] args)
{
int value = 6;
Console.WriteLine((Months)(value)); // do a cast
Console.ReadLine(); // the output of this is June
}
}
}

Hope this would help.




Re: Visual C# Express Edition month name converting problem

Rakesh k.m

thanks man.