what is this feature called in c# and which version of c# uses this

前端 未结 3 1449
感动是毒
感动是毒 2021-01-29 15:38

I am using this line of code in my project and haven`t seen this syntax.

 internal static StringBuilder a(this StringBuilder sb, string b) => sb.Append(b).Ap         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-29 15:58

    This line consists of two main features. The first is an extension method which is the method signature defined to the left of the lambda symbol (=>) and can be identified as an extension method as it uses the this keyword before the first parameter. The second is called an expression bodied function which is the part to the right of the lambda symbol.

    Extension methods

    Expression bodied functions

提交回复
热议问题