Files
Csharp/C#进阶/Lesson15_lambad表达式练习/Program.cs
T
2025-10-20 11:12:14 +08:00

51 lines
1.1 KiB
C#

namespace Lesson15_lambda表达式练习
{
class Program
{
static void Main(string[] args)
{
a1()();
a2()();
}
public static Action a1()
{
Action action = null;
for (int i = 1; i <= 10; i++)
{
int index = i;
action += delegate()
{
Console.WriteLine(index);
};
}
return action;
}
public static Action a2()
{
Action action = null;
for (int i = 1; i <= 10; i++)
{
int index = i;
action += () => Show(index);
}
return action;
}
public static Action a3()
{
Action action = null;
for (int i = 1; i <= 10; i++)
{
int index = i;
action += () => Show(index);
}
return action;
}
static void Show(int x)
{
Console.WriteLine(x);
}
}
}