为什么没有的String.Empty一个恒定的? [英] Why isn't String.Empty a constant?

查看:134
本文介绍了为什么没有的String.Empty一个恒定的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在净为什么的String.Empty只读,而不是一个恒定的?我只是想知道是否有人知道的理由是这一决定的背后。

In .Net why is String.Empty read only instead of a constant? I'm just wondering if anyone knows what the reasoning was behind that decision.

推荐答案

静态只读用于常量,而不是其原因是由于与非托管code使用,微软在<一个指示在这里href="http://www.microsoft.com/downloads/details.aspx?FamilyId=8C09FD61-3F26-4555-AE17-3121B4F51D4D&displaylang=en">Shared来源通用语言基础结构2.0发行。要看该文件是 sscli20 \ CLR的\ src \ BCL \ SYSTEM \ string.cs

The reason that static readonly is used instead of const is due to use with unmanaged code, as indicated by Microsoft here in the Shared Source Common Language Infrastructure 2.0 Release. The file to look at is sscli20\clr\src\bcl\system\string.cs.

在空不变持有空   字符串值。我们需要调用   String构造,使得   编译器不会将此标记为   文字。

The Empty constant holds the empty string value. We need to call the String constructor so that the compiler doesn't mark this as a literal.

标记此为文字将意味着   它不作为一个场显示   我们可以从本地访问。

Marking this as a literal would mean that it doesn't show up as a field which we can access from native.

我发现从这个方便的文章,在$ C $的CProject 。

这篇关于为什么没有的String.Empty一个恒定的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆