久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

string.Empty vs null.你使用哪個(gè)?

string.Empty vs null.Which one do you use?(string.Empty vs null.你使用哪個(gè)?)
本文介紹了string.Empty vs null.你使用哪個(gè)?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

最近工作的同事告訴我在設(shè)置字符串變量時(shí)不要使用string.Empty,而是使用null,因?yàn)樗鼤?huì)污染堆棧?

Recently a colleague at work told me not to use string.Empty when setting a string variable but use null as it pollutes the stack?

他說不要做

string myString=string.Empty; 但是做 string mystring=null;

這真的很重要嗎?我知道 string 是一個(gè)對(duì)象,所以它有點(diǎn)道理.

Does it really matter? I know string is an object so it sort of makes sense.

我知道這是一個(gè)愚蠢的問題,但您的觀點(diǎn)是什么?

I know is a silly question but what is your view?

推薦答案

nullEmpty 差別很大,不建議隨意切換.但兩者都沒有任何額外的成本",因?yàn)?Empty 是一個(gè)單一的固定引用(您可以多次使用它).

null and Empty are very different, and I don't suggest arbitrarily switching between them. But neither has any extra "cost", since Empty is a single fixed reference (you can use it any number of times).

堆棧上沒有由 ldsfld - 這種擔(dān)憂是......瘋狂.加載 null 可以說是稍微更便宜,但如果您不小心檢查值,可能會(huì)導(dǎo)致空引用異常.

There is no "pollution" on the stack caused by a ldsfld - that concern is.... crazy. Loading a null is arguably marginally cheaper, but could cause null-reference exceptions if you aren't careful about checking the value.

就我個(gè)人而言,我兩者都不使用...如果我想要一個(gè)空字符串,我使用 "" - 簡單明了.實(shí)習(xí)意味著這沒有每次使用的開銷.

Personally, I use neither... If I want an empty string I use "" - simple and obvious. Interning means this also has no per-usage overhead.

在 IL 級(jí)別,"" 和 Empty 之間的區(qū)別只是 ldstr 與 ldsfld - 但兩者都給出了相同的單個(gè)內(nèi)部字符串引用.此外,在最近的 .NET 版本中,JIT 直接攔截了這些,產(chǎn)生空字符串引用實(shí)際上沒有進(jìn)行靜態(tài)字段查找.基本上,除了可讀性之外,完全沒有理由關(guān)心任何一種方式.我只用".

At the IL level, the difference here between "" and Empty is just ldstr vs ldsfld - but both give the same single interned string reference. Furthermore, in more recent .NET versions the JIT has direct interception of these, yielding the empty string reference without actually doing a static field lookup. Basically, there is exactly no reason to care either way, except readability. I just use "".

這篇關(guān)于string.Empty vs null.你使用哪個(gè)?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to check if String is null(如何檢查字符串是否為空)
Equals(item, null) or item == null(Equals(item, null) 或 item == null)
Overriding == operator. How to compare to null?(覆蓋 == 運(yùn)算符.如何與空值進(jìn)行比較?)
What does the question mark in member access mean in C#?(成員訪問中的問號(hào)在 C# 中是什么意思?)
The || (or) Operator in Linq with C#(||(或)C# 中的 Linq 運(yùn)算符)
C# null coalescing operator equivalent for c++(C# 空合并運(yùn)算符等效于 C++)
主站蜘蛛池模板: 久久成人一区 | 国产一区二区精 | 亚洲免费在线观看 | 日韩成人| 精品国产一区二区三区在线观看 | 大陆一级毛片免费视频观看 | 国产毛片久久久久久久久春天 | 亚洲午夜精品一区二区三区他趣 | 亚州精品天堂中文字幕 | 无码一区二区三区视频 | 在线黄 | 91在线资源 | 91亚洲精品久久久电影 | 国产福利视频 | 99久久精品国产一区二区三区 | 日本在线中文 | 午夜视频在线播放 | 日韩av免费在线电影 | 日韩精品一区二区三区在线播放 | 国产亚洲精品精品国产亚洲综合 | 国产精品成人av | 日韩欧美在线观看 | 久久激情视频 | 午夜精品在线 | 色黄网站 | 久久免费观看一级毛片 | 91视频91| 成人看片在线观看 | 成人在线小视频 | 福利视频大全 | 日韩欧美在线一区 | 综合二区| 国产二区在线播放 | 91久久精品一区二区三区 | 99精品国自产在线 | 国产精品免费观看 | 美国黄色毛片 | 青青草原综合久久大伊人精品 | 羞羞免费网站 | 一级视频在线免费观看 | 福利久久|