111,076
社区成员




int[] data = new int[] { 1, 2, 3, 4, 5 };
List<Func<int>> actions = new List<Func<int>>();
foreach (int x in data)
{
actions.Add(() => x);
}
foreach (var foo in actions)
{
Console.WriteLine(foo());
}
int[] data = new int[] { 1, 2, 3, 4, 5 };
List<Func<int>> actions = new List<Func<int>>();
IEnumerator e = data.GetEnumerator();
int x = 0;
while (e.MoveNext())
{
x = (int)e.Current;
actions.Add(() => x);
}
foreach (var foo in actions)
{
Console.WriteLine(foo());
}
int[] data = new int[] { 1, 2, 3, 4, 5 };
List<Func<int>> actions = new List<Func<int>>();
IEnumerator e = data.GetEnumerator();
while (e.MoveNext())
{
int x = 0;
x = (int)e.Current;
actions.Add(() => x);
}
foreach (var foo in actions)
{
Console.WriteLine(foo());
}
int[] data = new int[] { 1, 2, 3, 4, 5 };
List<Func<int>> actions = new List<Func<int>>();
foreach (int x in data)
{
int x1 = x;
actions.Add(() => x1);
}
foreach (var foo in actions)
{
Console.WriteLine(foo());
}
for(int x=0;x<data.Length;x++)
{
actions.Add(() => x);
}
int[] data = new int[] { 1, 2, 3, 4, 5 };
var actions = from t in data select new { id=t };
foreach (var foo in actions)
{
Console.WriteLine(foo.id);
}