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

前端 未结 3 1485
感动是毒
感动是毒 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:59

    internal static StringBuilder a(this StringBuilder sb, string b)

    This part tells us that a is an extension method to StringBuilder. You can read more on extension methods here

    => sb.Append(b).Append("\n")

    These are functions with no statement body. Instead, you implement them with an expression following the function declaration. This is new feature in C# 6. and called expression-bodied function members. You can read more about them here

提交回复
热议问题