StringBuilder.Append Question

I would like to know the difference (if any) between:

StringBuilder sb = new StringBuilder(); 
sb.Append("xxx");
sb.Append("yyy");
sb.Append("zzz");

AND:

StringBuilder sb = new StringBuilder(); 
sb.Append("xxx")
  .Append("yyy")
  .Append("zzz");
+3
source share
4 answers

There is no difference, the latter case is called "Free Syntax".

+11
source

There is no functional difference. In the first case, you add rows StringBuilderin the same order in three operations. In the second case, you add the same lines to the same StringBuilderin the same statement.

There will be no noticeable difference in performance and absolutely no noticeable difference. You can choose one or the other stylistically.

+1
source

IL - , , ( , .), . , .

It always hit me, as StringBuilder.Appendalways came back. This makes StringBuilder an immutable structure when it is definitely not. This is also particularly annoying to F #, where you should explicitly ignore what it returns. But what are you going to do?

+1
source

There is no difference between them. But you can use the second option for a smaller line of code :)

0
source

Source: https://habr.com/ru/post/1726711/


All Articles