I am adding range of integers (101,105) using Func<> delegate.I suppose to get 101,102,..105 as output while executing the following.But I am getting 204,204,..... What went wrong?
class MainClass
{
static List<Func<int>> somevalues = new List<Func<int>>();
static void Main()
{
foreach (int r in Enumerable.Range(100, 105))
{
somevalues.Add(() => r);
}
ProcessList(somevalues);
Console.ReadKey(true);
}
static void ProcessList(List<Func<int>> someValues)
{
foreach (Func<int> function in someValues)
{
Console.WriteLine(function());
}
}
}