C#中类似JavaScript的匿名函数

cll*_*pse 0 javascript c# anonymous-methods anonymous-function

可以在C#中完成以下操作吗?:

var greeting = "Hello" + function ()
{
    return " World";
}() + "!";
Run Code Online (Sandbox Code Playgroud)

我想做一些事情(C#伪代码):

var cell = new TableCell { CssClass = "", Text = return delegate ()
{
     return "logic goes here";
}};
Run Code Online (Sandbox Code Playgroud)

基本上我想实现某些逻辑的内联作用域,而不是将该块逻辑移动到单独的方法中.

Sam*_*ell 9

var greeting = "Hello" + new Func<String>(() => " World")() + "!";
Run Code Online (Sandbox Code Playgroud)