{"id":172689,"date":"2013-04-17T00:53:03","date_gmt":"2013-04-16T20:53:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=172689"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=172689","title":{"rendered":"<span class=\"post_title\">StringBuilder \u043f\u0440\u043e\u0448\u043b\u043e\u0435 \u0438 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435<\/span>"},"content":{"rendered":"<div class=\"content html_format\">\n<h4>\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u041c\u043e\u044f \u043f\u0440\u043e\u0448\u043b\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u044b\u043b\u0430 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044f\u043c \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 String \u0432 .NET. \u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u044e, \u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u043b\u0430\u0441\u0441 StringBuilder.<\/p>\n<p>  \u041a\u0430\u043a \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 .NET \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u043c\u0438 (\u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f unsafe), \u0430 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u0441 \u043d\u0438\u043c\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u043a\u043e\u043d\u043a\u0430\u0442\u0435\u043d\u0430\u0446\u0438\u0438 \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430\u0445 \u043d\u0435 \u0441\u0430\u043c\u0430\u044f \u043b\u0443\u0447\u0448\u0430\u044f \u0438\u0434\u0435\u044f. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0438\u043c\u0435\u0435\u0442 \u0432\u0435\u0441\u044c\u043c\u0430 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439 \u043d\u0430 \u043f\u0430\u043c\u044f\u0442\u044c:<\/p>\n<pre><code class=\"cs\">string s = string.Empty; for (int i = 0; i &lt; 100; i++)  {     s += &quot;T&quot;;  } <\/code><\/pre>\n<p><a name=\"habracut\"><\/a><br \/>  \u0427\u0442\u043e \u0436\u0435 \u043f\u043b\u043e\u0445\u043e\u0433\u043e \u0432 \u044d\u0442\u043e\u043c \u043a\u043e\u0434\u0435? \u0410 \u0442\u043e, \u0447\u0442\u043e \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0434\u043b\u0438\u043d\u043e\u044e \u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u0431\u043e\u043b\u044c\u0448\u0435 \u0447\u0435\u043c \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0448\u0430\u0433\u0435 \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0438\u0437 \u0441\u0442\u0430\u0440\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0440\u0430\u0432\u043d\u043e:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/79f\/c9a\/f99\/79fc9af99c69a7feec6d0ac5b841451b.png\"\/> <\/p>\n<p>  \u0414\u0430\u043d\u043d\u0430\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u0435\u0441\u0442\u044c \u043d\u0435 \u0447\u0442\u043e \u0438\u043d\u043e\u0435, \u043a\u0430\u043a \u0441\u0443\u043c\u043c\u0430 \u0430\u0440\u0438\u0444\u043c\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441\u0438\u0438:<br \/>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/948\/9e7\/8ef\/9489e78ef5352fb557f292ebf16d8162.png\"\/><br \/>  \u0422\u043e \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u043a\u043e\u043d\u043a\u0430\u0442\u0435\u043d\u0430\u0446\u0438\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e O(n<sup>2<\/sup>), n \u2014 \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<p>  \u0414\u043b\u044f \u0443\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0432 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u043c \u043a\u043e\u0434\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043a\u043b\u0430\u0441\u0441 StringBuilder, \u0437\u043d\u0430\u044f, \u0447\u0442\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441 \u043d\u0438\u043c \u043d\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a \u0442\u0430\u043a\u0438\u043c \u0440\u0430\u0441\u0442\u0440\u0430\u0442\u0430\u043c \u043f\u0430\u043c\u044f\u0442\u0438 \u043a\u0430\u043a \u0441\u043e String. \u0424\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 StringBuilder \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443. <\/p>\n<pre><code class=\"cs\">var strB = new StringBuilder(); for (int i = 0; i &lt; 100; i++) {   strB.Append(&quot;T&quot;); } string str = strB.ToString(); <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u0445\u043e\u0442\u044c \u0438 \u043d\u0435 \u043b\u0438\u0448\u0435\u043d \u0432\u0441\u0435\u0445 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432 \u0438 \u0442\u0440\u0430\u0442\u0438\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c \u043d\u0430 \u0432\u0435\u0442\u0435\u0440, \u043d\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u044d\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0441\u0434\u0435\u0440\u0436\u0430\u043d\u043d\u043e, \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c \u043a\u043e\u0434\u043e\u043c.<\/p>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430 StringBuilder \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0430\u0441\u044c \u0432 .NET 4.0 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c\u0438 \u0432\u0435\u0440\u0441\u0438\u044f\u043c\u0438, \u0430 \u043f\u043e\u0442\u043e\u043c\u0443 \u044f \u0434\u0443\u043c\u0430\u044e, \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c, \u0447\u0442\u043e \u0436\u0435 \u0441 \u043d\u0438\u043c \u0441\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c.<\/p>\n<h4>StringBuilder \u0432 .NET 2.0<\/h4>\n<p>  \u041a\u043b\u0430\u0441\u0441 StringBuilder \u0432 .NET 2.0 \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u043e\u043b\u044f:<\/p>\n<pre><code class=\"cs\">public sealed class StringBuilder : ISerializable {     internal const int DefaultCapacity = 16;     private const string CapacityField = &quot;Capacity&quot;;     private const string MaxCapacityField = &quot;m_MaxCapacity&quot;;     private const string StringValueField = &quot;m_StringValue&quot;;     private const string ThreadIDField = &quot;m_currentThread&quot;;     internal IntPtr m_currentThread;     internal int m_MaxCapacity;     internal volatile string m_StringValue; &lt;------------------------------------- } <\/code><\/pre>\n<p>  <i>m_currentThread<\/i> \u2014 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u0442\u043e\u043a\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0441\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043e\u0431\u044a\u0435\u043a\u0442\u0430;<br \/>  <i>m_MaxCapacity<\/i> \u2014 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0435\u043c\u043a\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430;<br \/>   <i>m_StringValue<\/i> \u2014 \u0441\u0442\u0440\u043e\u043a\u0430, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0430\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u044b. <\/p>\n<p>  \u0424\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043a\u043b\u0430\u0441\u0441 StringBuilder \u0432\u043d\u0443\u0442\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u043c \u0442\u0438\u043f\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445 String. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u044b mscorlib.dll \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u043c\u0438, \u0442\u043e StringBuilder-\u0443 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0443\u044e\u0441\u044f \u0432 <i>m_StringValue<\/i>.<\/p>\n<p>  \u041f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 16 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u0430 \u043f\u0440\u0438 \u043d\u0435\u0445\u0432\u0430\u0442\u043a\u0435 \u043c\u0435\u0441\u0442\u0430 \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 StringBuilder \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u044e\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0443 \u0434\u043b\u0438\u043d\u043e\u044e \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u0438 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u0432\u043e \u0432\u043d\u043e\u0432\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0443\u044e \u0432\u0441\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 + \u043d\u043e\u0432\u044b\u0435. \u0423\u0434\u0432\u043e\u0435\u043d\u0438\u0435 \u0434\u043b\u0438\u043d\u044b \u0441\u0442\u0440\u043e\u043a\u0438 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 (O(n)) \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u0441\u0443\u0449\u0430 \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u0441\u0442\u0440\u043e\u043a\u0430\u043c. <\/p>\n<p>  \u0412\u0430\u0436\u043d\u044b\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u043a \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u0434\u0430\u043d\u0438\u0435 \u043d\u0443\u0436\u043d\u043e\u0439 \u0435\u043c\u043a\u043e\u0441\u0442\u0438 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 StringBuilder. \u0422\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u043d\u0430\u043c \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0435 \u0443\u0434\u0432\u043e\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0438 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438 \u043d\u0435\u0445\u0432\u0430\u0442\u043a\u0435 \u043f\u0430\u043c\u044f\u0442\u0438. \u041e\u0434\u043d\u0430\u043a\u043e, \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043b\u0438\u0448\u044c \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0437\u043d\u0430\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u0414\u043b\u044f \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u043a\u043e\u0434\u0430 \u044f \u0443\u0431\u0440\u0430\u043b \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432.<\/p>\n<h5><i>\u041c\u0435\u0442\u043e\u0434 Append()<\/i><\/h5>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">  public StringBuilder Append(string value)     {       if (value == null)         return this;       string currentString = this.m_StringValue;       IntPtr currentThread = Thread.InternalGetCurrentThread();       if (this.m_currentThread != currentThread)         currentString = string.GetStringForStringBuilder(currentString, currentString.Capacity);       int length = currentString.Length;       int requiredLength = length + value.Length;       if (this.NeedsAllocation(currentString, requiredLength)) \/\/\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043b\u0438 \u043c\u0435\u0441\u0442\u0430 \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432       { \t     \/\/\u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u0434\u043b\u0438\u043d\u043e\u044e \u0432 2 \u0440\u0430\u0437\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u0438 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0438\u0437 \u0441\u0442\u0430\u0440\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438          string newString = this.GetNewString(currentString, requiredLength);  \t     newString.AppendInPlace(value, length);               this.ReplaceString(currentThread, newString);  \/\/\u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0441\u0442\u0430\u0440\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u043e\u0432\u043e\u0439       }       else       {         currentString.AppendInPlace(value, length);  \t    this.ReplaceString(currentThread, currentString);        }     return this;    }    <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043b\u0438 \u043c\u0435\u0441\u0442\u0430 \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0435 \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u0435\u0441\u043b\u0438 \u0434\u0430, \u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u043c\u0435\u0441\u0442\u0435 \u0432 \u043d\u0435\u0437\u0430\u043d\u044f\u0442\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438, \u0438\u043d\u0430\u0447\u0435 \u0443\u0434\u0432\u043e\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0438 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0430\u0440\u043e\u0439 \u0438 \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438. <\/p>\n<h5><i>\u041c\u0435\u0442\u043e\u0434 Insert()<\/i><\/h5>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">  public StringBuilder Insert(int index, string value)     {       if (value == null)         return this.Insert(index, value, 0);       else         return this.Insert(index, value, 1);     }   public StringBuilder Insert(int index, string value, int count)     {       IntPtr tid;       string threadSafeString = this.GetThreadSafeString(out tid);       int length = threadSafeString.Length;       if (value != null && value.Length != 0)       {         if (count != 0)         {           int requiredLength;           try           {                 requiredLength = checked (length + value.Length * count);\/\/\u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0434\u043b\u0438\u043d\u0443 \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438           }           catch (OverflowException ex)           {             throw new OutOfMemoryException();           }              if (this.NeedsAllocation(threadSafeString, requiredLength))\/\/\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043b\u0438 \u043c\u0435\u0441\u0442\u0430 \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432           { \t\t    \/\/\u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u0434\u043b\u0438\u043d\u043e\u044e \u0432 2 \u0440\u0430\u0437\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u0438 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0438\u0437 \u0441\u0442\u0430\u0440\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438             string newString = this.GetNewString(threadSafeString, requiredLength);\t               newString.InsertInPlace(index, value, count, length, requiredLength);\/\/\u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b             this.ReplaceString(tid, newString);\/\/\u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0441\u0442\u0430\u0440\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u043e\u0432\u043e\u0439           }           else           {             threadSafeString.InsertInPlace(index, value, count, length, requiredLength);             this.ReplaceString(tid, threadSafeString);           }           return this;         }       }       return this;     } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043b\u0438 \u043c\u0435\u0441\u0442\u0430 \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0435 \u0434\u043b\u044f \u0432\u0441\u0442\u0430\u0432\u043a\u0438 \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u0443\u0434\u0432\u0430\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u043b\u0438 \u0436\u0435 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430 \u043c\u0435\u0441\u0442\u0435 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u0431\u0435\u0437 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u0430.<\/p>\n<h5><i>\u041c\u0435\u0442\u043e\u0434 Remove()<\/i><\/h5>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">public StringBuilder Remove(int startIndex, int length)     {       IntPtr tid;       string threadSafeString = this.GetThreadSafeString(out tid);       int length1 = threadSafeString.Length;        \/\/\u0443\u0434\u0430\u043b\u044f\u0435\u043c \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b, \u0441\u0434\u0432\u0438\u0433\u0430\u044f \u043e\u0441\u0442\u0430\u0432\u0448\u0443\u044e\u0441\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438 \u0432\u043b\u0435\u0432\u043e       threadSafeString.RemoveInPlace(startIndex, length, length1);       this.ReplaceString(tid, threadSafeString);\/\/\u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0441\u0442\u0430\u0440\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u043e\u0432\u043e\u0439       return this;     } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b, \u0441\u0434\u0432\u0438\u0433\u0430\u044f \u043e\u0441\u0442\u0430\u0432\u0448\u0443\u044e\u0441\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438 \u0432\u043b\u0435\u0432\u043e. \u041f\u0440\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u0434\u0432\u0438\u0433\u0430\u0442\u044c \u043d\u0435 \u043d\u0430\u0434\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0441 \u043a\u043e\u043d\u0446\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0435\u043c \u0438\u0437 \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<h5><i>\u041c\u0435\u0442\u043e\u0434 ToString()<\/i><\/h5>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">public override string ToString()     {       string str = this.m_StringValue;       if (this.m_currentThread != Thread.InternalGetCurrentThread() || 2 * str.Length &lt; str.ArrayLength)          return string.InternalCopy(str);\/\/\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043a\u043e\u043f\u0438\u044e \u0441\u0442\u0440\u043e\u043a\u0438       str.ClearPostNullChar();       this.m_currentThread = IntPtr.Zero; \t       return str; \/\/\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443     } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434, \u043a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043b\u0438\u0431\u043e \u043a\u043e\u043f\u0438\u044e \u0441\u0442\u0440\u043e\u043a\u0438, \u043b\u0438\u0431\u043e \u0441\u0442\u0440\u043e\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u0442. \u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u0431\u044b\u0441\u0442\u0440\u043e, \u043e\u0434\u043d\u0430\u043a\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u044b\u0437\u043e\u0432 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u0441\u0442\u0440\u043e\u043a\u0438. \u041a\u043b\u0430\u0441\u0441 StringBuilder \u0432 .NET 2.0 \u0434\u0435\u043b\u0430\u0435\u0442 \u0443\u043f\u043e\u0440 \u0438\u043c\u0435\u043d\u043d\u043e \u043d\u0430 \u0431\u044b\u0441\u0442\u0440\u043e\u0442\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<p>  \u0412 \u043e\u0431\u0449\u0435\u043c, \u043a\u043b\u0430\u0441\u0441 StringBuilder \u0432 .NET 2.0 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e. \u041e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u0430 \u043f\u0440\u0438 \u043d\u0435\u0445\u0432\u0430\u0442\u043a\u0435 \u043c\u0435\u0441\u0442\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u0434\u043b\u0438\u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439. \u0422\u0430\u043a\u043e\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u0443\u0434\u0432\u043e\u0435\u043d\u0438\u044f \u0434\u043b\u0438\u043d\u044b \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438, \u0447\u0442\u043e \u043d\u0430 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u043b\u0443\u0447\u0448\u0435 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u043e\u0439. \u041e\u0434\u043d\u0430\u043a\u043e, \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0434\u043b\u0438\u043d\u0430\u0445 \u0441\u0442\u0440\u043e\u043a \u0438 \u044d\u0442\u043e \u043d\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e. \u041a\u0441\u0442\u0430\u0442\u0438, \u0438\u0437-\u0437\u0430 \u0441\u0432\u043e\u0435\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430, \u0441\u0442\u0440\u043e\u043a\u0430 \u0447\u0430\u0441\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u0432 \u043a\u0443\u0447\u0435 \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432(LOH), \u0447\u0442\u043e \u0442\u0430\u043a \u0436\u0435 \u043d\u0438 \u0435\u0441\u0442\u044c \u0445\u043e\u0440\u043e\u0448\u043e.<\/p>\n<h4>StringBuilder \u0432 .NET 4.0<\/h4>\n<p>  \u041a\u0430\u043a \u044f \u0443\u0436\u0435 \u0441\u043a\u0430\u0437\u0430\u043b, \u0432 .NET 4.0 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430 StringBuilder \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u0430\u0441\u044c. \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0432\u043c\u0435\u0441\u0442\u043e String \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f Char[], \u0430 \u0441\u0430\u043c \u043a\u043b\u0430\u0441\u0441 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u0432\u044f\u0437\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a StringBuilder-\u043e\u0432 \u043f\u043e\u0434\u043e\u0431\u043d\u043e RopeString. <\/p>\n<p>  \u041f\u0440\u0438\u0447\u0438\u043d\u0430 \u0442\u0430\u043a\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0430: \u043f\u0440\u0438 \u0442\u0430\u043a\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u0440\u0438 \u0435\u0435 \u043d\u0435\u0445\u0432\u0430\u0442\u043a\u0435, \u0447\u0442\u043e \u043f\u0440\u0438\u0441\u0443\u0449\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u042d\u0442\u043e \u0442\u0430\u043a \u0436\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434 ToString() \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0430 \u043c\u0435\u0442\u043e\u0434 Append() \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e \u0432\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f StringBuilder: \u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u043e\u0432 Append(), \u0430 \u0437\u0430\u0442\u0435\u043c \u043e\u0434\u0438\u043d \u0432\u044b\u0437\u043e\u0432 ToString().<\/p>\n<p>  \u041a\u043b\u0430\u0441\u0441 StringBuilder \u0432 .NET 4.0 \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u043e\u043b\u044f:<\/p>\n<pre><code class=\"cs\">public sealed class StringBuilder : ISerializable   {     internal const int DefaultCapacity = 16;     internal const int MaxChunkSize = 8000;     internal char[] m_ChunkChars; &lt;-------------------------------------     internal StringBuilder m_ChunkPrevious; &lt;-------------------------------------     internal int m_ChunkLength;     internal int m_ChunkOffset;     internal int m_MaxCapacity;     private const string CapacityField = &quot;Capacity&quot;;     private const string MaxCapacityField = &quot;m_MaxCapacity&quot;;     private const string StringValueField = &quot;m_StringValue&quot;;     private const string ThreadIDField = &quot;m_currentThread&quot;;   } <\/code><\/pre>\n<p>  <i>m_ChunkChars<\/i> \u2014 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0441\u0432\u044f\u0437\u043d\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430 (\u043a\u0443\u0441\u043e\u0447\u043a\u0430 \u0441\u0442\u0440\u043e\u043a\u0438);<br \/>  <i>m_ChunkPrevious<\/i> \u2014 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 (StringBuilder) \u0432 \u0441\u043f\u0438\u0441\u043a\u0435;<br \/>  <i>m_ChunkLength<\/i> \u2014 \u0440\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0441\u043f\u0438\u0441\u043a\u0430 (\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432);<br \/>  <i>m_ChunkOffset<\/i> \u2014 \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0441\u0442\u0440\u043e\u043a\u043e\u0439 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 (\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0434\u043b\u0438\u043d\u0430);<br \/>  <i>m_MaxCapacity<\/i> \u2014 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0435\u043c\u043a\u043e\u0441\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 StringBuilder.<\/p>\n<p>  \u0412 .NET Framework 4 \u0438 .NET Framework 4.5 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 StringBuilder \u043f\u0443\u0442\u0435\u043c \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 StringBuilder(Int32, Int32) \u0438 \u0434\u043b\u0438\u043d\u0430 \u0438 \u0435\u043c\u043a\u043e\u0441\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 StringBuilder \u043c\u043e\u0436\u0435\u0442 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0437\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 MaxCapacity. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438 \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 Append \u0438 AppendFormat.<\/p>\n<p>  \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0441\u043f\u0438\u0441\u043a\u0430 <i>MaxChunkSize <\/i>\u0440\u0430\u0432\u043d\u0430 8000. \u041a\u0430\u043a \u0432\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0435 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a. \u0412\u043e\u0442 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<p>  <b>We want to keep chunk arrays out of large object heap (&lt; 85K bytes ~ 40K chars) to be sure. Making the maximum chunk size big means less allocation code called, but also more waste in unused characters and slower inserts \/ replaces.<\/p>\n<p>  \u041c\u044b \u0445\u043e\u0442\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u043d\u0435 \u043f\u043e\u043f\u0430\u0434\u0430\u043b \u0432 \u043a\u0443\u0447\u0443 \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u0414\u0435\u043b\u0430\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0441\u043f\u0438\u0441\u043a\u0430 (\u043a\u0443\u0441\u043e\u0447\u043a\u0430) \u0431\u043e\u043b\u044c\u0448\u0438\u043c, \u0437\u043d\u0430\u0447\u0438\u043b\u043e \u0431\u044b, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438 \u043f\u0430\u043c\u044f\u0442\u0438, \u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u043c\u0438 \u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 insert \/ replace \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435.<\/b><\/p>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<\/p>\n<h5><i>\u041c\u0435\u0442\u043e\u0434 Append()<\/i><\/h5>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">public unsafe StringBuilder Append(string value)     {       if (value != null)       {         char[] chArray = this.m_ChunkChars;         int index = this.m_ChunkLength;         int length = value.Length;         int num = index + length;         if (num &lt; chArray.Length)\/\/ \u0415\u0441\u043b\u0438 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043c\u0435\u0441\u0442\u0430 \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0435 \u0434\u043b\u044f \u0432\u0441\u0442\u0430\u0432\u043a\u0438 \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438         {           if (length &lt;= 2)           {             if (length &gt; 0)               chArray[index] = value[0];             if (length &gt; 1)               chArray[index + 1] = value[1];           }           else           {             fixed (char* smem = value)               fixed (char* dmem = &chArray[index])                 string.wstrcpy(dmem, smem, length);           }           this.m_ChunkLength = num;         }         else           this.AppendHelper(value);       }       return this;     }    private unsafe void AppendHelper(string value)     {       fixed (char* chPtr = value)         this.Append(chPtr, value.Length);     }   internal unsafe StringBuilder Append(char* value, int valueCount)     {       \/\/ \u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f       int num1 = valueCount + this.m_ChunkLength;       if (num1 &lt;= this.m_ChunkChars.Length)       {         StringBuilder.ThreadSafeCopy(value, this.m_ChunkChars, this.m_ChunkLength, valueCount);         this.m_ChunkLength = num1;       }       else       {  \t\/\/ \u041a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u043f\u0435\u0440\u0432\u0443\u044e \u0447\u0430\u0441\u0442\u044c(\u043a\u0443\u0441\u043e\u0447\u0435\u043a)         int count = this.m_ChunkChars.Length - this.m_ChunkLength;         if (count &gt; 0)         {           StringBuilder.ThreadSafeCopy(value, this.m_ChunkChars, this.m_ChunkLength, count);           this.m_ChunkLength = this.m_ChunkChars.Length;         } \t    \/\/ \u0423\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0431\u0438\u043b\u0434\u0435\u0440, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044f \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u043a\u0443\u0441\u043e\u0447\u0435\u043a         int num2 = valueCount - count;         this.ExpandByABlock(num2); \t    \/\/ \u041a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0432\u0442\u043e\u0440\u0443\u044e \u0447\u0430\u0441\u0442\u044c (\u043a\u0443\u0441\u043e\u0447\u0435\u043a)         StringBuilder.ThreadSafeCopy(value + count, this.m_ChunkChars, 0, num2);         this.m_ChunkLength = num2;       }       return this;     } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041c\u0435\u0442\u043e\u0434 Append() \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: \u0435\u0441\u043b\u0438 \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0434\u043b\u044f \u0432\u0441\u0442\u0430\u0432\u043a\u0438 \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u043d\u0435\u0435, \u0435\u0441\u043b\u0438 \u0436\u0435 \u043d\u0435\u0442, \u0442\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0442\u0430 \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f, \u0430 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043d\u0435 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u043b\u043e\u0441\u044c, \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441\u043f\u0438\u0441\u043a\u0430 (\u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 StringBuilder-a), \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0434\u043b\u0438\u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0440\u0430\u0432\u043d\u0430 \u0434\u043b\u0438\u043d\u0435 \u0432\u0441\u0435\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u043b\u0438\u0431\u043e \u0434\u043b\u0438\u043d\u0435 \u043e\u0441\u0442\u0430\u0432\u0448\u0435\u0439\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435. \u041e\u0434\u043d\u0430\u043a\u043e, \u043a\u0430\u043a \u0431\u044b\u043b\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e, \u0432\u044b\u0448\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 8000.<\/p>\n<p>  \u0412 \u043e\u0431\u0449\u0435\u043c, \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u0438\u043d\u044b \u043d\u043e\u0432\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0441\u043f\u0438\u0441\u043a\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cs\">int length = Math.Max(minBlockCharCount, Math.Min(this.Length, 8000)) <\/code><\/pre>\n<p>  \u0433\u0434\u0435 minBlockCharCount \u2014 \u043e\u0441\u0442\u0430\u0432\u0448\u0430\u044f\u0441\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0435\u0435 \u0447\u0430\u0441\u0442\u0438 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440.<\/p>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u043e\u0434\u0430<\/p>\n<pre><code class=\"cs\">StringBuilder s = new StringBuilder (); for (int i = 0; i &lt; 10000; i++) {   s.Append (&quot;T&quot;); } <\/code><\/pre>\n<p>  \u0434\u043b\u0438\u043d\u044b \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u043f\u0438\u0441\u043a\u0430 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0432\u043d\u044b: <b>8000<\/b>, 4092, 2048, 1024, 512, 256, 128, 64, 32, 16, 16.<\/p>\n<p>  \u041f\u0440\u0438 \u0442\u0430\u043a\u0438\u0445 \u0434\u043b\u0438\u043d\u0430\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0441\u0438\u043c\u0432\u043e\u043b\u0443 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430 O(1), \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u043f\u0438\u0441\u043a\u0430 \u043d\u0435 \u0442\u0430\u043a \u043c\u043d\u043e\u0433\u043e. <\/p>\n<h5><i>\u041c\u0435\u0442\u043e\u0434 Insert()<\/i><\/h5>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">public unsafe StringBuilder Insert(int index, string value)     {       if (value != null)       {         fixed (char* chPtr = value)           this.Insert(index, chPtr, value.Length);       }       return this;     } private unsafe void Insert(int index, char* value, int valueCount)     {       if (valueCount &lt;= 0)         return;       StringBuilder chunk;       int indexInChunk;       \/\/\u0412\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u044f \u043d\u043e\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441\u043f\u0438\u0441\u043a\u0430 (StringBuilder)       this.MakeRoom(index, valueCount, out chunk, out indexInChunk, false);       this.ReplaceInPlaceAtChunk(ref chunk, ref indexInChunk, value, valueCount);     } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041c\u0435\u0442\u043e\u0434 Insert() \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: \u0435\u0441\u043b\u0438 \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435 \u0441\u043f\u0438\u0441\u043a\u0430(StringBuilder-\u0435) \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043c\u0435\u0441\u0442\u0430 \u0434\u043b\u044f \u0432\u0441\u0442\u0430\u0432\u043a\u0438, \u0442\u043e \u0438\u043c\u0435\u044e\u0449\u0438\u0435\u0441\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0441\u0434\u0432\u0438\u0433\u0430\u044e\u0442\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u0434\u0430\u0442\u044c \u043c\u0435\u0441\u0442\u043e \u043d\u043e\u0432\u043e\u043c\u0443 \u0442\u0435\u043a\u0441\u0442\u0443. \u0418\u043d\u0430\u0447\u0435 \u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441\u043f\u0438\u0441\u043a\u0430 (StringBuilder), \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u043b\u0438\u0441\u044c. \u041f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u043d\u0435 \u0441\u043c\u0435\u0449\u0430\u044e\u0442\u0441\u044f \u0432\u043b\u0435\u0432\u043e.<\/p>\n<p>  \u0427\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u043e\u0434\u0430?<\/p>\n<pre><code class=\"cs\">StringBuilder s = new StringBuilder (); for (int i = 0; i &lt; 10000; i++) {   s.Insert (0, &quot;T&quot;); } <\/code><\/pre>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043a\u043e\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0435\u0433\u043e Append(), \u043f\u0440\u0438\u0447\u0435\u043c \u0432\u0435\u0441\u044c\u043c\u0430 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u043e!<\/p>\n<p>  \u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0441\u043f\u0438\u0441\u043e\u043a StringBuilder-\u043e\u0432 \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0434\u043b\u0438\u043d\u0443 16 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0447\u0435\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0441\u0438\u043c\u0432\u043e\u043b\u0443 \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0439, \u0447\u0435\u043c \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u0438\u043d\u0435 \u0441\u043f\u0438\u0441\u043a\u0430, \u0442\u043e \u0435\u0441\u0442\u044c O(n). <\/p>\n<h5><i>\u041c\u0435\u0442\u043e\u0434 Remove()<\/i><\/h5>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">public StringBuilder Remove(int startIndex, int length)     {       if (this.Length == length && startIndex == 0)       { \t    \/\/ \u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f. \u0415\u0441\u043b\u0438 \u043c\u044b \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0432\u0441\u044e \u0441\u0442\u0440\u043e\u043a\u0443.         this.Length = 0;         return this;       }       else       {         if (length &gt; 0)         {           StringBuilder chunk;           int indexInChunk;           this.Remove(startIndex, length, out chunk, out indexInChunk);         }         return this;       }     } private void Remove(int startIndex, int count, out StringBuilder chunk, out int indexInChunk)     {       int num = startIndex + count; \t  \/\/\u041d\u0430\u0445\u043e\u0434\u0438\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0441\u043f\u0438\u0441\u043a\u0430(\u043a\u0443\u0441\u043e\u0447\u043a\u0438) \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f.       chunk = this;       StringBuilder stringBuilder = (StringBuilder) null;       int sourceIndex = 0;       while (true)       {         if (num - chunk.m_ChunkOffset &gt;= 0)         {           if (stringBuilder == null)           {             stringBuilder = chunk;             sourceIndex = num - stringBuilder.m_ChunkOffset;           }           if (startIndex - chunk.m_ChunkOffset &gt;= 0)             break;         }         else           chunk.m_ChunkOffset -= count;         chunk = chunk.m_ChunkPrevious;       }       indexInChunk = startIndex - chunk.m_ChunkOffset;       int destinationIndex = indexInChunk;       int count1 = stringBuilder.m_ChunkLength - sourceIndex;       \/\/\u0415\u0441\u043b\u0438 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u043a\u0443\u0441\u043e\u0447\u043a\u0438 \u043d\u0435 \u0440\u0430\u0432\u043d\u044b       if (stringBuilder != chunk)       {         destinationIndex = 0; \t    \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u043f\u043e\u0441\u043b\u0435 startIndex \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0441\u043f\u0438\u0441\u043a\u0430(\u043a\u0443\u0441\u043e\u0447\u043a\u0430)           chunk.m_ChunkLength = indexInChunk; \t    \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u043c\u0435\u0436\u0434\u0443 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u043c \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c \u043a\u0443\u0441\u043e\u0447\u043a\u043e\u043c.         stringBuilder.m_ChunkPrevious = chunk;         stringBuilder.m_ChunkOffset = chunk.m_ChunkOffset + chunk.m_ChunkLength; \t    \/\/ \u0415\u0441\u043b\u0438 \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u043b\u044c \u0432 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u043c \u043a\u0443\u0441\u043e\u0447\u043a\u0435 \u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u043a\u0438\u043d\u0443\u0442\u044c \u0432\u0435\u0441\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441\u043f\u0438\u0441\u043a\u0430(\u043a\u0443\u0441\u043e\u0447\u0435\u043a)             if (indexInChunk == 0)         {           stringBuilder.m_ChunkPrevious = chunk.m_ChunkPrevious;           chunk = stringBuilder;         }       }       stringBuilder.m_ChunkLength -= sourceIndex - destinationIndex;       if (destinationIndex == sourceIndex)  \/\/ \u0418\u043d\u043e\u0433\u0434\u0430 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f         return; \t\/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u043a\u0443\u0441\u043e\u0447\u043a\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u044f \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0435\u0441\u044f \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0432\u043b\u0435\u0432\u043e       StringBuilder.ThreadSafeCopy(stringBuilder.m_ChunkChars, sourceIndex, stringBuilder.m_ChunkChars, destinationIndex, count1);     } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u043b\u0430\u0441\u044c. \u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0430\u0434\u043e \u0443\u0447\u0435\u0441\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043b\u0430 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u0441\u043c\u0435\u0449\u0430\u044f \u0438\u0445 \u0432\u043b\u0435\u0432\u043e. \u0417\u0434\u0435\u0441\u044c \u0436\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 (StringBuilder-\u0430) \u0432 \u0441\u043f\u0438\u0441\u043a\u0435.<\/p>\n<h5><i>\u041c\u0435\u0442\u043e\u0434 ToString()<\/i><\/h5>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">public override unsafe string ToString()     {       if (this.Length == 0)         return string.Empty;       string str = string.FastAllocateString(this.Length);       StringBuilder stringBuilder = this;       fixed (char* chPtr = str)       {         do         {           if (stringBuilder.m_ChunkLength &gt; 0)           {             char[] chArray = stringBuilder.m_ChunkChars;             int num = stringBuilder.m_ChunkOffset;             int charCount = stringBuilder.m_ChunkLength;             fixed (char* smem = chArray)               string.wstrcpy(chPtr + num, smem, charCount);           }           stringBuilder = stringBuilder.m_ChunkPrevious;         }         while (stringBuilder != null);       }       return str;     } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u043f\u043e \u0432\u0441\u0435\u043c\u0443 \u0441\u0432\u044f\u0437\u043d\u043e\u043c\u0443 \u0441\u043f\u0438\u0441\u043a\u0443 StringBuilder-\u043e\u0432 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u043f\u0438\u0441\u043a\u0430 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443. <\/p>\n<h4>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/h4>\n<p>  \u041f\u043e\u0436\u0430\u043b\u0443\u0439, \u0441\u0430\u043c\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u2014 \u044d\u0442\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0432\u0435\u0440\u0441\u0438\u044f\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u0430. <\/p>\n<p>  <b>\u0422\u0435\u0441\u0442 1. \u0421\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0439 \u0434\u043b\u0438\u043d\u044b. <\/b><\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/ff5\/6bf\/956\/ff56bf9560066482f1d89ba07cb81771.png\"\/><\/p>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u043f\u0440\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0434\u043b\u0438\u043d\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u043e\u0432\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0432\u0430\u0435\u0442 \u0441\u0442\u0430\u0440\u043e\u0439. \u041e\u043d\u043e \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0432\u0435\u0434\u044c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0441\u043f\u0438\u0441\u043a\u0430(StringBuilder) \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0434\u043b\u0438\u043d\u0435, \u0435\u043c\u043a\u043e\u0441\u0442\u0438, \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0438 \u043e\u0442 \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 + \u0434\u043b\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 overhead. \u041d\u043e \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u0438\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435 16384, \u0441\u0442\u0430\u0440\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0432\u0430\u0442\u044c (\u0438\u0437-\u0437\u0430 \u0443\u0434\u0432\u043e\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0441\u0442\u0440\u043e\u043a\u0438, \u043e\u043d\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043c\u043d\u043e\u0433\u043e \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432). <\/p>\n<p>  <b>\u0422\u0435\u0441\u0442 2. \u041c\u0435\u0442\u043e\u0434 Append()<\/b><\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/3b8\/b64\/97b\/3b8b6497b473f0c0a0d10cb774cbb1d6.png\"\/><\/p>\n<p>  \u041f\u043e\u0436\u0430\u043b\u0443\u0439, \u044d\u0442\u043e \u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 \u043c\u0435\u0442\u043e\u0434, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u043e\u0432\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0431\u0435\u0436\u0434\u0430\u0435\u0442. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0440\u0438 \u043d\u0435\u0445\u0432\u0430\u0442\u043a\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0443\u0434\u0432\u0430\u0438\u0432\u0430\u0442\u044c \u0434\u043b\u0438\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u043d\u0435\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f, \u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435, <b>\u043f\u043e\u0447\u0442\u0438 \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430 (\u0442\u043e\u0447\u043d\u0435\u0435 \u0432 1,8 \u0440\u0430\u0437).<\/b><\/p>\n<p>  <b>\u0422\u0435\u0441\u0442 3. \u041c\u0435\u0442\u043e\u0434 Insert()<\/b><\/p>\n<p>  \u0411\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u0432\u0441\u0442\u0430\u0432\u043a\u0443 \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 \u0443\u0436\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u0443\u044e \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438, \u0434\u043b\u0438\u043d\u043e\u044e 1000 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432.<\/p>\n<p>  1. \u0412\u0441\u0442\u0430\u0432\u043a\u0430 \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u0441\u0442\u0440\u043e\u043a\u0438<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/6f7\/0da\/c6d\/6f70dac6d0d9fa3613034fb60b0ef9a1.png\"\/><\/p>\n<p>  2. \u0412\u0441\u0442\u0430\u0432\u043a\u0430 \u0432 \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0438<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/94e\/e3e\/e5f\/94ee3ee5f1dccf3979cef3c47b5d5098.png\"\/><\/p>\n<p>  3. \u0412\u0441\u0442\u0430\u0432\u043a\u0430 \u0432 \u043a\u043e\u043d\u0435\u0446 \u0441\u0442\u0440\u043e\u043a\u0438<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/97b\/f02\/9a1\/97bf029a1f76f07f57e544fda74e65e6.png\"\/><\/p>\n<p>  \u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0438\u0437\u043b\u0438\u0448\u043d\u0435 \u2014 \u043d\u043e\u0432\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0438 \u0432\u0441\u0442\u0430\u0432\u043a\u0435 \u0432 \u043b\u044e\u0431\u043e\u0435 \u043c\u0435\u0441\u0442\u043e.<\/p>\n<p>  <b>\u0422\u0435\u0441\u0442 4. \u041c\u0435\u0442\u043e\u0434 Remove()<\/b><\/p>\n<p>  \u0411\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 10 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0438\u0437 \u0441\u0442\u0440\u043e\u043a\u0438 \u0443\u0436\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u043e\u0439 \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0438\u0441\u0447\u0435\u0440\u043f\u0430\u0435\u043c \u0435\u0435.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/365\/2b9\/91b\/3652b991beceb0b359260b81a8c2142f.png\"\/><\/p>\n<p>  \u041d\u043e\u0432\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u044b\u0438\u0433\u0440\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u043f\u043e\u0447\u0442\u0438 \u0438\u0437 \u043b\u044e\u0431\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u043c\u0435\u0449\u0430\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u043e\u0441\u0442\u0430\u0432\u0448\u0435\u0439\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u0432\u043b\u0435\u0432\u043e (\u0442\u043e\u0447\u043d\u0435\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f, \u043d\u043e \u043d\u0435 \u0442\u0430\u043a \u0447\u0430\u0441\u0442\u043e \u0438 \u043c\u043d\u043e\u0433\u043e \u043a\u0430\u043a \u0440\u0430\u043d\u044c\u0448\u0435).<\/p>\n<p>  <b>\u0422\u0435\u0441\u0442 5. \u041c\u0435\u0442\u043e\u0434 ToString()<\/b><\/p>\n<p>  \u041a\u0430\u043a \u0431\u044b\u043b\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e \u0432\u044b\u0448\u0435, \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u043d\u0430 \u043e\u043f\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0430 (\u043f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435), \u0430 \u043d\u043e\u0432\u0430\u044f \u0432\u044b\u043d\u0443\u0436\u0434\u0435\u043d\u0430 \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u043e \u043a\u0443\u0441\u043a\u0430\u043c, \u043e\u0431\u0445\u043e\u0434\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441\u0432\u044f\u0437\u043d\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/5a3\/76c\/1fa\/5a376c1fa1337a5497f0e6d3d58d56d0.png\"\/><\/p>\n<p>  \u041d\u043e\u0432\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0435\u0441\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0430 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 Insert(), \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441\u043f\u0438\u0441\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u0438\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432(StringBuilder-\u043e\u0432) \u0434\u043b\u0438\u043d\u043e\u044e \u0432 16 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432.<\/p>\n<p>  <b>\u0422\u0435\u0441\u0442 6. \u041e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u0443 <\/b><\/p>\n<p>  \u0423\u0447\u0438\u0442\u044b\u0432\u0430\u044f, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c StringBuilder \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u0432\u044f\u0437\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a, \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0441\u0442\u0440\u043e\u043a\u0435 \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u0443 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0434\u043e\u0440\u043e\u0433\u043e\u0441\u0442\u043e\u044f\u0449\u0435\u0439. \u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u043e\u043d \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043b\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 Insert.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/b1e\/6e5\/cde\/b1e6e5cde4f058efdf7c423741a44606.png\"\/><\/p>\n<p>  <b>\u0422\u0435\u0441\u0442 7. \u041e\u0431\u044b\u0447\u043d\u044b\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439: \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u044b\u0437\u043e\u0432\u043e\u0432 Append(), \u0430 \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u0437\u043e\u0432 ToString()<\/b><\/p>\n<p>  \u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0434\u0430\u043d\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044e: \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 Append(), \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0434\u0438\u043d \u0432\u044b\u0437\u043e\u0432 ToString(). \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u0430\u0441\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u0432 \u0440\u0430\u0441\u0447\u0435\u0442\u0435 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0439.<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/888\/1eb\/58d\/8881eb58d9ca11bc2a9a990fcc4482d4.png\"\/><\/p>\n<h4>\u0412\u044b\u0432\u043e\u0434<\/h4>\n<p>  \u041a\u0430\u043a \u043c\u044b \u0443\u0432\u0438\u0434\u0435\u043b\u0438, \u043a\u043b\u0430\u0441\u0441 StringBuilder \u0432 .NET 2.0 \u0431\u044b\u043b \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d \u043d\u0430 \u0431\u044b\u0441\u0442\u0440\u043e\u0442\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u0435\u0442\u043e\u0434\u0430 ToString(), \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0432 .NET 4.0 \u043d\u0430 \u0431\u044b\u0441\u0442\u0440\u043e\u0442\u0443 \u043c\u0435\u0442\u043e\u0434\u0430 Append(). \u041d\u043e\u0432\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 Append() \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e\u0447\u0442\u0438 \u0432 2 \u0440\u0430\u0437\u0430 \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u043c\u0435\u0442\u043e\u0434\u044b Insert() \u0438 ToString() \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435. \u041d\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443, \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0434\u0430\u043d\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044e: \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0440\u0430\u0437 \u043c\u0435\u0442\u043e\u0434 Append(), \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 ToString(), \u0442\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438\u043c\u0435\u0435\u0442 \u043c\u0435\u0441\u0442\u043e.<\/p>\n<p>  \u0423\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u043d\u043e\u0432\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u0430, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043b\u0438\u0448\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 Append() \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043a\u043b\u0430\u0441\u0441 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043d\u0430\u0437\u0432\u0430\u0442\u044c StringAppender *)    \t \t\t   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/172689\/\"> http:\/\/habrahabr.ru\/post\/172689\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">\n<h4>\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u041c\u043e\u044f \u043f\u0440\u043e\u0448\u043b\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u044b\u043b\u0430 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044f\u043c \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 String \u0432 .NET. \u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u044e, \u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u043b\u0430\u0441\u0441 StringBuilder.<\/p>\n<p>  \u041a\u0430\u043a \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 .NET \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u043c\u0438 (\u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f unsafe), \u0430 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u0441 \u043d\u0438\u043c\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u043a\u043e\u043d\u043a\u0430\u0442\u0435\u043d\u0430\u0446\u0438\u0438 \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430\u0445 \u043d\u0435 \u0441\u0430\u043c\u0430\u044f \u043b\u0443\u0447\u0448\u0430\u044f \u0438\u0434\u0435\u044f. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0438\u043c\u0435\u0435\u0442 \u0432\u0435\u0441\u044c\u043c\u0430 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439 \u043d\u0430 \u043f\u0430\u043c\u044f\u0442\u044c:<\/p>\n<pre><code class=\"cs\">string s = string.Empty; for (int i = 0; i &lt; 100; i++)  {     s += &quot;T&quot;;  } <\/code><\/pre>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-172689","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/172689","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=172689"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/172689\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=172689"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=172689"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=172689"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}