添加Lesson15

This commit is contained in:
2025-10-20 11:12:14 +08:00
parent b4d3ced472
commit b1d4959956
5 changed files with 179 additions and 0 deletions
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,50 @@
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);
}
}
}