Are there any official ways to write an Immediately Invoked Function Expression?

后端 未结 6 1391
自闭症患者
自闭症患者 2021-02-04 02:21

Something like this:

var myObject = new MyClass()
{
    x = \" \".Select(y =>
    {
        //Do stuff..
        if (2 + 2 == 5)
            return \"I like c         


        
6条回答
  •  清酒与你
    2021-02-04 02:53

    Here is what my coworker came up with:

    var myObject = new { 
        x = new Func(() => {return 2;})() 
    };
    

    Note that this is based Alexei's answer.

提交回复
热议问题