Code

Code

GetListItems using Func Generic in C#


Func, ListItem[]> GetListItems = (items) =>
{
    List list = new List();
    foreach(int i in items)
    {
        string item = i.ToString("D2");
        list.Add(new ListItem()
        {
            Text = item,
            Value = item
        });
    }

    return list.ToArray();
};

dropListYear.Items.AddRange(GetListItems(Enumerable.Range(DateTime.Now.Year - 99, 100).Reverse().ToList()));
dropListMonth.Items.AddRange(GetListItems(Enumerable.Range(1, 12).ToList()));
dropListDay.Items.AddRange(GetListItems(Enumerable.Range(1, 31).ToList()));