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

后端 未结 6 1417
自闭症患者
自闭症患者 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:38

    For real code make it a function... For entertainment purposes C# equivalent of JavaScript IIFE is more direct than Select:

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

提交回复
热议问题