How to call anonymous function in C#?

后端 未结 2 1099
感动是毒
感动是毒 2020-12-24 02:53

I am interested if it\'s possible using C# to write a code analogous to this Javascript one:

var v = (function()
{
    return \"some value\";
})()

2条回答
  •  情深已故
    2020-12-24 03:22

    Here's how you could then utilize such a construct to enclose context - closure-

    Control.Click += new Func((x) =>
    new System.EventHandler(delegate(object sender, EventArgs e)
    {
    
    }))(valueForX);
    

提交回复
热议问题