Robert MacLean
29 August 2011
William Brander responded to my last nugget on compiler optimisation with a tweet about another one:
So what does that look like? Let’s look at the code we type:
string interesting = "first"; interesting += " second"; interesting += " third" + " forth"; interesting = interesting + " fifth"; interesting = interesting + " sixth" + " seventh"; Console.WriteLine(interesting);
And this optimises the concatenation to a single line and drops the variable. Interesting use of braces for fifth & sixth though, when I switched += to =.
Console.WriteLine(("first" + " second" + " third forth") + " fifth" + " sixth seventh");