Abe*_*ler 3 .net c# string performance
从性能的角度来看,使用"Example1"会更好吗?我假设"Example2"会在每次迭代中在堆上创建一个新字符串,而"Example1"则不会...
例1:
StringBuilder letsCount = new StringBuilder("Let's count! ");
string sep = ", ";
for(int i=; i< 100; i++)
{
letsCount.Append(i + sep);
}
Run Code Online (Sandbox Code Playgroud)
例2:
StringBuilder letsCount = new StringBuilder("Let's count! ");
for(int i=; i< 100; i++)
{
letsCount.Append(i + ", ");
}
Run Code Online (Sandbox Code Playgroud)