I have a simple console application in .net 4.5.
public class Program { public static void Main() { string s1 = "s1"; string s2 = "s1"; Console.WriteLine(ReferenceEquals(s1, s2)); } }
This gives true because of string interning. However, when I add the CompilationRelaxations attribute to the AssemblyInfo file, I'm still seeing true as the output.
[assembly: CompilationRelaxations(CompilationRelaxations.NoStringInterning)]
Even adding the attribute to my Program class does not seem to change the output. [CompilationRelaxations(CompilationRelaxations.NoStringInterning)]
Changing it to a .net 4.0 application does not have any effect either.
What am I missing?
public static string s1() {return "s1";}
to it. Then call that function fro yourmain
, and compare the result to an"s1"
constant defined inside"main"
. My guess is that this would compare equal only with the interning turned on. – Sergey Kalinichenko[MethodImpl(MethodImplOptions.NoOptimization)]
doesn't help. – Cheng Chen