Wednesday, August 12, 2015

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");
}

10 comments:

  1. .Net is most preferred programming language among software developers all over the world. It is also considered as most trusted and effective platform to build high performing desktop or enterprise application. DOT NET Training Institutes in Chennai

    ReplyDelete
  2. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete
  3. great and nice blog thanks sharing..I just want to say that all the information you have given here is awesome...Thank you very much for this one.
    web design Company
    web development Company
    web design Company in chennai
    web development Company in chennai
    web design Company in India
    web development Company in India

    ReplyDelete