Getting all the months in the any Financial Year using C#

Introduction:
This article explains how to get all the months in the any Financial Year using C#.







Method- 1

public static List<string> GetStringMonthsList(string FinacialYear)
        {
            string fist = FinacialYear.Split('-')[0].ToString();
            string Second = FinacialYear.Split('-')[1].ToString();
            List<string> result = new List<string>();
            result.Add("April" + "-" + fist);
            result.Add("May" + "-" + fist);
            result.Add("June" + "-" + fist);
            result.Add("July" + "-" + fist);
            result.Add("August" + "-" + fist);
            result.Add("September" + "-" + fist);
            result.Add("October" + "-" + fist);
            result.Add("November" + "-" + fist);
            result.Add("December" + "-" + fist);
            result.Add("January" + "-" + Second);
            result.Add("February" + "-" + Second);
            result.Add("March" + "-" + Second);

            return result;
        }

Method- 2

public static SelectList GetMonthsList(string Month)
{
  string months = Month;//2015-2016
  string[] parts = months.Split('-');
  string fist = parts[0].ToString();
  string Second = parts[1].ToString();
  var result = new List<SelectListItem>();
  result.Add(new SelectListItem() { Text = "April" + "-" + fist, Value = "4" });
  result.Add(new SelectListItem() { Text = "May" + "-" + fist, Value = "5" });
  result.Add(new SelectListItem() { Text = "June" + "-" +fist, Value = "6" });
  result.Add(new SelectListItem() { Text = "July" + "-" + fist, Value = "7" });
  result.Add(new SelectListItem() { Text = "August" + "-" + fist, Value = "8" });
  result.Add(new SelectListItem() { Text = "September" + "-" + fist, Value = "9" });
  result.Add(new SelectListItem() { Text = "October" + "-" + fist, Value = "10" });
  result.Add(new SelectListItem() { Text = "November" + "-" + fist, Value = "11" });
  result.Add(new SelectListItem() { Text = "December" + "-" + fist, Value = "12" });
  result.Add(new SelectListItem() { Text = "January" + "-" + Second, Value = "1" });
  result.Add(new SelectListItem() { Text = "February" + "-" + Second, Value = "2" });
  result.Add(new SelectListItem() { Text = "March" + "-" + Second, Value = "3" });
            
  return new SelectList(result, "Value", "Text");
}
Ashwani
Ashwani

This is a short biography of the post author. Maecenas nec odio et ante tincidunt tempus donec vitae sapien ut libero venenatis faucibus nullam quis ante maecenas nec odio et ante tincidunt tempus donec.

7 comments: