How to make inline functions in C#

后端 未结 6 469
一向
一向 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 07:58

    Yes.

    You can create anonymous methods or lambda expressions:

    Func PrefixTrimmer = delegate(string x) {
        return x ?? "";
    };
    Func PrefixTrimmer = x => x ?? "";
    

提交回复
热议问题