How to make inline functions in C#

后端 未结 6 472
一向
一向 2020-12-04 07:24

I\'m using Linq To XML

new XElement(\"Prefix\", Prefix == null ? \"\" : Prefix)

but I want to do some computation to the prefix before addi

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-04 08:05

    C# 7 adds support for local functions

    Here is the previous example using a local function

    void Method()
    {
        string localFunction(string source)
        {
            // add your functionality here
            return source ;
        };
    
       // call the inline function
       localFunction("prefix");
    }
    

提交回复
热议问题