本文介绍了Stringbuilder和concatentaion问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Stringbuilder里面是concatentaion邪恶的?


下面首选的语法是什么?


语法#1

Dim sb As New StringBuilder

sb.Append(" Line 1"& vbCrLf)

sb.Append(" Line 2&& ; vbCrLf)

sb.Append(" Line 3& vbCrLf)


语法#2

Dim sb As新的StringBuilder

sb.Append(" Line 1")

sb.Append(vbCrLf)

sb.Append(" Line 2" ;)

sb.Append(vbCrLf)

sb.Append(" Line 3")

sb.Append(vbCrLf)


-

Joe Fallon

Is concatentaion inside of a Stringbuilder "evil"?

Which is the preferred syntax below?

Syntax #1
Dim sb As New StringBuilder
sb.Append("Line 1" & vbCrLf)
sb.Append("Line 2" & vbCrLf)
sb.Append("Line 3" & vbCrLf)

Syntax #2
Dim sb As New StringBuilder
sb.Append("Line 1")
sb.Append(vbCrLf)
sb.Append("Line 2")
sb.Append(vbCrLf)
sb.Append("Line 3")
sb.Append(vbCrLf)

--
Joe Fallon

推荐答案




我投票给#1,因为编译器将删除连接并且

存储连接的字符串文字(Line 1 \ r\\\
")。因此,#1

将有更好的性能,因为方法调用较少。


-

Herfried K. Wagner [ MVP]

< URL:http://dotnet.mvps.org/>

< URL:http://dotnet.mvps.org/dotnet/ faqs />



I vote for #1, because the compiler will remove the concatenation and
store the concatenated string literal instead ("Line 1\r\n"). So, #1
will have better performance because there are fewer method calls.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>





我投票给#1,因为编译器将删除串联并且存储连接的字符串文字(Line 1 \\\\ n)。因此,#1
将有更好的性能,因为方法调用较少。

- Herfried K. Wagner [MVP]
< URL:http: //dotnet.mvps.org/>
< URL:http://dotnet.mvps.org/dotnet/faqs/>



I vote for #1, because the compiler will remove the concatenation and
store the concatenated string literal instead ("Line 1\r\n"). So, #1
will have better performance because there are fewer method calls.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>



这篇关于Stringbuilder和concatentaion问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 18:25