The compiler is typically pretty smart when it comes to string literals. Take a look at your code with Reflector and the debugger disassembler.
static void Main(string[] args)
{
string a = "A" + "B" + "C" + "D" + "E" + "F" + "G";
Console.WriteLine(a);
}
//reflector:
private static void Main(string[] args)
string text1 = "ABCDEFG";
Console.WriteLine(text1);
//but it not smarter than your application:
string a = "A";
string b = "B";
string c = "C";
string d = a + b + c;
string text1 = "A";
string text2 = "B";
string text3 = "C";
string text4 = text1 + text2 + text3;
//and now for a slightly different question and answer:
string b = "ABCDEFG";
take a look at the debug disassembly and you will see that both a and b are initialized with the same literal: string a = "A" + "B" + "C" + "D" + "E" + "F" + "G"; 00000029 mov eax,dword ptr ds:[0227307Ch] 0000002f mov edi,eax string b = "ABCDEFG";00000031 mov eax,dword ptr ds:[0227307Ch] 00000037 mov esi,eax
Remember Me
a@href@title, strike
Powered by: newtelligence dasBlog 2.0.7226.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2012, Andrew Robinson
E-mail