{"id":6949,"date":"2022-09-06T01:57:14","date_gmt":"2022-09-05T20:27:14","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/"},"modified":"2022-09-06T01:57:14","modified_gmt":"2022-09-05T20:27:14","slug":"solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/","title":{"rendered":"[Solved] How Much Faster is StringBuilder respect of concat operator + in C# .Net [duplicate]"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-22537324\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"22537324\" data-parentid=\"22536411\" data-score=\"4\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>The Microsoft Developer Network has a great comparison:<\/p>\n<blockquote>\n<p>Although StringBuilder and String both represent sequences of<br \/>\n  characters, they are implemented differently. String is an immutable<br \/>\n  type. That is, each operation that appears to modify a String object<br \/>\n  actually creates a new string.<\/p>\n<p>For example, the call to the String.Concat method in the following C#<br \/>\n  example appears to change the value of a string variable named value.<br \/>\n  In fact, the Concat method returns a value object that has a different<br \/>\n  value and address from the value object that was passed to the method.<br \/>\n  Note that the example must be compiled using the \/unsafe compiler<br \/>\n  option. For routines that perform extensive string manipulation (such<br \/>\n  as apps that modify a string numerous times in a loop), modifying a<br \/>\n  string repeatedly can exact a significant performance penalty. The<br \/>\n  alternative is to use StringBuilder, which is a mutable string class.<br \/>\n  Mutability means that once an instance of the class has been created,<br \/>\n  it can be modified by appending, removing, replacing, or inserting<br \/>\n  characters. A StringBuilder object maintains a buffer to accommodate<br \/>\n  expansions to the string. New data is appended to the buffer if room<br \/>\n  is available; otherwise, a new, larger buffer is allocated, data from<br \/>\n  the original buffer is copied to the new buffer, and the new data is<br \/>\n  then appended to the new buffer.<\/p>\n<\/blockquote>\n<p>The recommended usage for a <code>String<\/code> is:<\/p>\n<ul>\n<li>\n<p>When the number of changes that your application will make to a string are quite small.  In these instances <code>StringBuilder<\/code> may offer negligible or no performance improvement over <code>String<\/code>.  (Due to the way the <code>StringBuilder<\/code> handles its buffer)<\/p>\n<\/li>\n<li>\n<p>When you are performing a fix number of concatenation operations, particularly with <code>String<\/code> literals.  The Compiler should combine these into one single operation.<\/p>\n<\/li>\n<li>\n<p>When you have to perform extensive search operations while you are building a <code>String<\/code>.  <code>StringBuilder<\/code> lacks search methods such as <code>IndexOf<\/code> or <code>StartsWith<\/code>.  You&#8217;ll have to convert your <code>StringBuilder<\/code> object to a <code>String<\/code> for these operations which may negate the performance.<\/p>\n<\/li>\n<\/ul>\n<p>The recommended usage for <code>StringBuilder<\/code>:<\/p>\n<ul>\n<li>\n<p>When you expect your application to make unknown number of changes to a string at design time (an example would be loops\/random number strings).<\/p>\n<\/li>\n<li>\n<p>When you expect your application to make significant changes to a <code>string<\/code>.<\/p>\n<\/li>\n<\/ul>\n<p><strong>So the question really shouldn&#8217;t be, &#8220;Which performs better&#8221;, it should be &#8220;Under which circumstance is one more ideal than another?&#8221;<\/strong><\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\"><\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved How Much Faster is StringBuilder respect of concat operator + in C# .Net [duplicate] <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] The Microsoft Developer Network has a great comparison: Although StringBuilder and String both represent sequences of characters, they are implemented differently. String is an immutable type. That is, each operation that appears to modify a String object actually creates a new string. For example, the call to the String.Concat method in the following C# &#8230; <a title=\"[Solved] How Much Faster is StringBuilder respect of concat operator + in C# .Net [duplicate]\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/\" aria-label=\"More on [Solved] How Much Faster is StringBuilder respect of concat operator + in C# .Net [duplicate]\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[352,324],"class_list":["post-6949","post","type-post","status-publish","format-standard","hentry","category-solved","tag-net","tag-c"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] How Much Faster is StringBuilder respect of concat operator + in C# .Net [duplicate] - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] How Much Faster is StringBuilder respect of concat operator + in C# .Net [duplicate] - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] The Microsoft Developer Network has a great comparison: Although StringBuilder and String both represent sequences of characters, they are implemented differently. String is an immutable type. That is, each operation that appears to modify a String object actually creates a new string. For example, the call to the String.Concat method in the following C# ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-05T20:27:14+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] How Much Faster is StringBuilder respect of concat operator + in C# .Net [duplicate]\",\"datePublished\":\"2022-09-05T20:27:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/\"},\"wordCount\":412,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\".net\",\"c++\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/\",\"name\":\"[Solved] How Much Faster is StringBuilder respect of concat operator + in C# .Net [duplicate] - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-09-05T20:27:14+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] How Much Faster is StringBuilder respect of concat operator + in C# .Net [duplicate]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] How Much Faster is StringBuilder respect of concat operator + in C# .Net [duplicate] - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] How Much Faster is StringBuilder respect of concat operator + in C# .Net [duplicate] - JassWeb","og_description":"[ad_1] The Microsoft Developer Network has a great comparison: Although StringBuilder and String both represent sequences of characters, they are implemented differently. String is an immutable type. That is, each operation that appears to modify a String object actually creates a new string. For example, the call to the String.Concat method in the following C# ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/","og_site_name":"JassWeb","article_published_time":"2022-09-05T20:27:14+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] How Much Faster is StringBuilder respect of concat operator + in C# .Net [duplicate]","datePublished":"2022-09-05T20:27:14+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/"},"wordCount":412,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":[".net","c++"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/","url":"https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/","name":"[Solved] How Much Faster is StringBuilder respect of concat operator + in C# .Net [duplicate] - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-09-05T20:27:14+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-how-much-faster-is-stringbuilder-respect-of-concat-operator-in-c-net-duplicate\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] How Much Faster is StringBuilder respect of concat operator + in C# .Net [duplicate]"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/6949","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=6949"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/6949\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=6949"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=6949"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=6949"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}