Hi Every one,
I read in various books, forums and believed that irrespective of string manipulation on literals string == operator will always return true, here is a very simple program and its output i want to to know why string1==string4 returns false ? even though both are string literals. Does it mean a string concatenation on string literals will return a new object ?
string1==string2 is true
string1==string4 is false
The difference is between compile time and runtime.
If a string expression can be evaluated at compile time, it will be put into the string pool.
It will evaluate the concatenation it can at compile time.
In this specific example, the concatenation of string5 and string6 is done at runtime (string5 is not constant at compile time) and thus results in a new string.
However consider the following examples:
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop