Possible Duplicate:
Does C# optimize the concatenation of string literals?
I just found out that we write a line like this:
string s = "string";
s = s + s; // this translates to s = string.concat("string", "string");
However I opened the string class through reflector and I don't see where this + operator is overloaded? I can see that == and != are overloaded.
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
public static bool operator ==(string a, string b)
{
return string.Equals(a, b);
}
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
public static bool operator !=(string a, string b)
{
return !string.Equals(a, b);
}
So why does concat gets called when we use + for combining strings?
Thanks.