lambda
This commit is contained in:
32
BasicGramms/BasicGramms/BasicLambda.cs
Normal file
32
BasicGramms/BasicGramms/BasicLambda.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BasicGramms
|
||||
{
|
||||
|
||||
internal class BasicLambda
|
||||
{
|
||||
private delegate int Calc(int x, int y);
|
||||
private delegate void CalcVoid() ;
|
||||
|
||||
public void DoTest()
|
||||
{
|
||||
// lambda
|
||||
Calc cal = (int x, int y) => x + y;
|
||||
Console.WriteLine(cal(2, 5));
|
||||
|
||||
// anonymous method
|
||||
cal = delegate (int x, int y)
|
||||
{
|
||||
return x + y;
|
||||
};
|
||||
Console.WriteLine(cal(10, 7));
|
||||
|
||||
CalcVoid calcVoid = () => Console.WriteLine("This is void lambda");
|
||||
calcVoid();
|
||||
}
|
||||
}
|
||||
}
|
@@ -16,8 +16,11 @@ namespace BasicGramms
|
||||
//BasicEvent evt = new BasicEvent();
|
||||
//evt.DoTest();
|
||||
|
||||
BasicEventUser evtUser = new BasicEventUser();
|
||||
evtUser.DoTest();
|
||||
//BasicEventUser evtUser = new BasicEventUser();
|
||||
//evtUser.DoTest();
|
||||
|
||||
BasicLambda lambda = new BasicLambda();
|
||||
lambda.DoTest();
|
||||
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
Reference in New Issue
Block a user