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

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

    For some reason it's really hard to get implicitly typed delegates, but it's not impossible if you write your own static methods for it.

    public static class Func {
       public static Func Create(
          Func pFunc
       ) =>
         pFunc;       
    }
    
    ...
    
    x = Func.Create(() => "result")();
    
    x = Func.Create(() => {
       // complex logic to create a value
    })();
    

提交回复
热议问题