为什么建议多&QUOT更多的String.Empty;"? [英] Why is string.Empty more recommended than ""?

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

问题描述

为什么建议多

是因为当编译器解析代码和来,编译器会准备读一个字符串?但在的String.Empty 编译器甚至不准备读一个字符串?

Is it because when the compiler is parsing the code and a " comes, the compiler will get ready to read a string? but in string.Empty the compiler will not even get ready to read a string?

推荐答案

有另外一个原因。

常量,因为其性质,是一个静态引用在一些应用领域的所有线程共享一个实例,而文字会在<$ C结束$ C> N 一个空字符串的实例。

Constants, because of their nature, are a static reference to a single instance shared by all threads in some application domain, while a literal would end in N instances of an empty string.

这就是为什么的String.Empty 建议恒定的使用空的字符串,显然,正如其他人所说,它增加了可读性。

That's why the string.Empty constant is recommended over using the empty "" string literal, and obviously, as others have said, it increases readability.

编辑:由于对方表示,也许N
实例,是因为实习的字符串不是绝对正确的
,但我
谈论理论和高层次
事实,这将是我们
应在账户中令人难以置信的
高级语言如C#隐藏$ b $的那些b个最底层的详细信息。

As other said, maybe "N instances" isn't absolutely correct because of string interning, but I'm talking about theory and high-level facts, which would be the ones that we should take in account in incredibly high-level languages like C# hiding most of low-level details.

这是所有关于
你怎么编写的长时间的讨论?你将是
生产或过度
的完美主义者,失去了
当前一代的伟大
产能优势,管理内存和
硬件抽象语言和
运行时?

It's all about the long discussion of "how you code? are you going to be productive or excessively perfectionist, losing great productivity advantages of current-generation, managed-memory and hardware-abstracted languages and runtimes?

这篇关于为什么建议多&QUOT更多的String.Empty;&QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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