相关疑难解决方法(0)

为什么String.Empty不是常量?

在.Net中为什么String.Empty只读而不是常量?我只是想知道是否有人知道该决定背后的原因是什么.

.net string constants readonly

182
推荐指数
3
解决办法
2万
查看次数

为什么默认情况下只有文本字符串保存在实习池中?

为什么默认情况下只有文字字符串保存在实习池中?

来自MSDN的示例:

String s1 = "MyTest";
String s2 = new StringBuilder().Append("My").Append("Test").ToString(); 
String s3 = String.Intern(s2); 
Console.WriteLine("s1 == '{0}'", s1);
Console.WriteLine("s2 == '{0}'", s2);
Console.WriteLine("s3 == '{0}'", s3);
Console.WriteLine("Is s2 the same reference as s1?: {0}", (Object)s2==(Object)s1); 
Console.WriteLine("Is s3 the same reference as s1?: {0}", (Object)s3==(Object)s1);

/*
This example produces the following results:
s1 == 'MyTest'
s2 == 'MyTest'
s3 == 'MyTest'
Is s2 the same reference as s1?: False
Is s3 the same reference as s1?: True
*/
Run Code Online (Sandbox Code Playgroud)

.net c# compiler-construction string clr

29
推荐指数
2
解决办法
5422
查看次数

什么是"原生"和"文字"关键字

我在C#文章中多次使用原生文字 "关键字".他们的意思是什么?

例子:

string.Empty文章:

Empty常量保存空字符串值.我们需要调用String构造函数,以便编译器不会将其标记为 文字.将其标记为文字将意味着它不会显示为我们可以从本机访问的字段.

C#vs Java维基百科文章:

简单/原始类型
两种语言都支持许多内置类型,这些类型按值而不是通过引用进行复制和传递.Java将这些类型称为原始类型,而它们在C#中称为简单类型.简单/原始类型通常具有来自底层处理器体系结构的本机支持.

.net c# keyword

9
推荐指数
1
解决办法
1399
查看次数

标签 统计

.net ×3

c# ×2

string ×2

clr ×1

compiler-construction ×1

constants ×1

keyword ×1

readonly ×1