{"id":5176,"date":"2014-03-30T19:26:27","date_gmt":"2014-03-30T19:26:27","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/what-is-different-between-these-to-ways-in-writeline-duplicate-collection-of-common-programming-errors\/"},"modified":"2014-03-30T19:26:27","modified_gmt":"2014-03-30T19:26:27","slug":"what-is-different-between-these-to-ways-in-writeline-duplicate-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/what-is-different-between-these-to-ways-in-writeline-duplicate-collection-of-common-programming-errors\/","title":{"rendered":"what is different between these to ways in writeline()? [duplicate]-Collection of common programming errors"},"content":{"rendered":"<p><strong>For:<\/strong><\/p>\n<pre><code>Console.WriteLine(\"Hi there, {0} {1}!\", userName, userSurname);\n<\/code><\/pre>\n<p>Your first call resolves to: <code>Console.WriteLine(string,object,object)<\/code><\/p>\n<p>IN IL<\/p>\n<pre><code> IL_000d:  ldstr      \"Hi there, {0} {1}!\"\n IL_0012:  ldloc.0\n IL_0013:  ldloc.1\n IL_0014:  call       void [mscorlib]System.Console::WriteLine(string,\n                                                                object,\n                                                                object)\n<\/code><\/pre>\n<p><strong>For:<\/strong><\/p>\n<pre><code>Console.WriteLine(\"Hi there, \" + userName + \" \" + userSurname + \"!\" );\n<\/code><\/pre>\n<p>While your second statement makes a call to <code>string.Concat<\/code> method.<\/p>\n<pre><code>IL_0042:  call       string [mscorlib]System.String::Concat(string[])\nIL_0047:  call       void [mscorlib]System.Console::WriteLine(string)\n<\/code><\/pre>\n<p>If you look at the code using ILSpy, you will see that the part where you have used <code>+<\/code> for string concatenation is replaced with call to <code>string.Concat<\/code> method<\/p>\n<pre><code>string userName = \"Test\";\nstring userSurname = \"Test2\";\nConsole.WriteLine(\"Hi there, {0} {1}!\", userName, userSurname);\nConsole.WriteLine(string.Concat(new string[]\n{\n    \"Hi there, \",\n    userName,\n    \" \",\n    userSurname,\n    \"!\"\n}));\n<\/code><\/pre>\n<p>With respect to difference in performance, I believe if there is any its going to be negligible.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For: Console.WriteLine(&#8220;Hi there, {0} {1}!&#8221;, userName, userSurname); Your first call resolves to: Console.WriteLine(string,object,object) IN IL IL_000d: ldstr &#8220;Hi there, {0} {1}!&#8221; IL_0012: ldloc.0 IL_0013: ldloc.1 IL_0014: call void [mscorlib]System.Console::WriteLine(string, object, object) For: Console.WriteLine(&#8220;Hi there, &#8221; + userName + &#8221; &#8221; + userSurname + &#8220;!&#8221; ); While your second statement makes a call to string.Concat method. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5176","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5176","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5176"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5176\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}