???C#?????????????
???????????? ???????[ 2015/3/5 11:28:29 ] ????????C# ??????? ????????
???????????????????
???????????Lambda??????????????????????????????????Щ?????????
????var result = name => name;
??????Щд???????????????c#?????????????????var??????????????????????????????? ????????????????????????????????????????С??????е?name??????????????????????????????
????var result = (string name) => name;
????Func<string?? string> result2 = (string name) => name;
????Expression<Func<string?? string>> result3 = (string name) => name;
???????????????name??????????????????????????????????????????????????????????????????Func<string?? string>???????Expression<Func<string?? string>>?????
????dynamic result = name => name;
????dynamic result1 = (Func<string??string>)(name => name);
??????dynamic??????????????????????????У???????????????????
????Func<string?? string> function = name => name;
????DynamicFunction df = function;
???????????func??У?????????????????????DynamicFunction?????????????????????????????????Func<string?? string>??DynamicFunction??2???????????????
???????c#?е???
?????????????????????????????????????????????????????????????????????? ??????c#?????б????
????Func<Func<int>> A = () =>
????{
????var age = 18;
????return () => //B????
????{
????return age;
????};
????};
????var result = A()();
??????????????????????? ???????????????????????????????????????
????C#?????????????????????????????????????????????????????????????????????????(??????????????/?????)??????????????????????????????????????
??????????????????B?????????????A?????age????????????????A??????B?????????????????B????????????????age?????????淶???
????int age = 16;
????void Display()
????{
????Console.WriteLine(age);
????int age = 18;
????Console.WriteLine(age);
????}
??????????????δ????????????????鵽??????????age???????????????????age??(??JSundefined??)??
????Func<int> C = () =>
????{
????var age = 19;
????return age;
????};
?????????????????????C?????A???????????C?????е?age??????? ???????????????????????????????????? ?????????????????????????
???????????????????????????A??????????????????????? ???????????????????鵽B???????A??????????????????????????????x?????A?????????age?????x??????(?????????)??A???????????????x??????????????????????????????(?????)??
class Program1
{
static Func<Func<int>> CachedAnonymousMethodDelegate2;
static void Main(string[] args)
{
Func<Func<int>> func = new Func<Func<int>>(Program1.B);
int num = func()();
}
static Func<int> B()
{
DisplayClass cl = new DisplayClass();
cl.age = 18;
return new Func<int>(cl.A);
}
}
sealed class DisplayClass
{
public int age;
public int A()
{
return this.age;
}
}
???????????????????????????
????static Func<int?? int> GetClosureFunction()
????{
????int val = 10;
????Func<int?? int> interAdd = x => x + val;
????Console.WriteLine(interAdd(10));
????val = 30;
????Console.WriteLine(interAdd(10));
????return interAdd;
????}
????Console.WriteLine(GetClosureFunction()(30));
????????????20??40??60?? ??????????????????val???????????????????????val????????????????????????????????????????????????????val????????????????????????interAdd??????????????????????????val??????????????????????????????(???)??????
??????????????js?????????????????????????£?
????function A() {
????var age = 18;
????return function () {
????return age;
????}
????}
????A()();
????????????
???????????????????????????????????????????????????????????????????????????????????????????????????????
?????????????????????? A()???????????????A()()??????A()??????????????????????????????????????????????????????????á?
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11