gpt4 book ai didi

c# - CompilationRelaxations.NoStringInterning 实际上是如何工作的?

转载 作者:太空狗 更新时间:2023-10-30 00:19:56 26 4
gpt4 key购买 nike

我在演示 NoStringInterning 时遇到问题

[assembly: System.Runtime.CompilerServices.CompilationRelaxations(System.Runtime.CompilerServices.CompilationRelaxations.NoStringInterning)]

class Program
{
static void Main(string[] args)
{
String s1 = "Friday";
String s2 = "Friday";
String s3 = "Friday";
String s4 = "Friday";
String s5 = "Friday";
String s6 = "Friday";
String s7 = "Friday";
String s8 = "Friday";
String s9 = "Friday";
// etc...
Console.WriteLine(Object.ReferenceEquals(s1, s2));
Console.WriteLine(Object.ReferenceEquals(s1, s3));
Console.WriteLine(Object.ReferenceEquals(s1, s4));
Console.WriteLine(Object.ReferenceEquals(s1, s5));
Console.WriteLine(Object.ReferenceEquals(s1, s6));
Console.WriteLine(Object.ReferenceEquals(s1, s7));
Console.WriteLine(Object.ReferenceEquals(s1, s8));
Console.WriteLine(Object.ReferenceEquals(s1, s9));
// etc...

我已经尝试使用 .NET CLR 2、3、4.. 作为输出,我得到的只是一堆 True。我期待一堆 False!

最佳答案

documentation声明该属性:

Marks an assembly as not requiring string-literal interning.

换句话说,它不会阻止编译器进行字符串驻留,只是提供一个不需要它的提示。这方面的文档有点稀疏,但这似乎也是 this MSDN forum post 中的结论。 .

关于c# - CompilationRelaxations.NoStringInterning 实际上是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15601916/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com