does the following code create 3 new strings each time the method is called and evaluated to true or is the compile smart enough to compile the right hand side strings into constants?
if (somestring == "Test" || someString == "Test1")
{
...
NotifyPropertyChanged("Name");
}
They are literals, which means that they are loaded with the
ldstropcode, i.e.The impact of this is that: anything that goes through
ldstris automatically interned, so, you can do this:So: yes, the first time that method is used, the literals
"Test","Test1"and"Name"may be created, but only once. After that, the same existing string instances are used. This is guaranteed byldstr: