54681

I have to bind a drop down box with years starting from 2008 to current year in C#. How can I achieve it.
Answer1:
You can build a sequence of integers with System.Linq.Enumerable.Range
:
var startYear = 2008;
myDropDownList.DataSource = Enumerable.Range(startYear, DateTime.Now.Year - startYear + 1);
myDropDownList.DataBind();
<strong>Update:</strong> In .NET 2.0 you can implement your own Range operator with an iterator:
public static IEnumerable<int> Range (int start, int count)
{
int end = start + count;
for (int i = start; i < end; i++)
yield return i;
}