Sponsored Ad

Friday, March 19, 2010

Get Month Name from Month Number | Convert Given Month to Month Name in C#

This utility converts the given month number to month name. You have to just pass the month number and it will return month name as return string.

 

Please note that we have used this method and static, you can change and make it non static method.

 

        /// <summary>
       /// Converts the given month number to month name.
       /// </summary>
       public static string GetStringMonthName(int MonthNumber)
       {
           string strmonthname = "";
           switch (MonthNumber)
           {
               case 1:
                   strmonthname = "January";
                   break;
               case 2:
                   strmonthname = "February";
                   break;
               case 3:
                   strmonthname = "March";
                   break;
               case 4:
                   strmonthname = "April";
                   break;
               case 5:
                   strmonthname = "May";
                   break;
               case 6:
                   strmonthname = "June";
                   break;
               case 7:
                   strmonthname = "July";
                   break;
               case 8:
                   strmonthname = "August";
                   break;
               case 9:
                   strmonthname = "September";
                   break;
               case 10:
                   strmonthname = "October";
                   break;
               case 11:
                   strmonthname = "November";
                   break;
               case 12:
                   strmonthname = "December";
                   break;

           }

           return strmonthname;
       }

0 comments:

Post a Comment

Sponsored Ad

Website Update

Followers