添加Lesson15
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user