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

string.Empty vs null.你使用哪個?

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

問題描述

最近工作的同事告訴我在設(shè)置字符串變量時不要使用string.Empty,而是使用null,因為它會污染堆棧?

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 是一個對象,所以它有點道理.

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

我知道這是一個愚蠢的問題,但您的觀點是什么?

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

推薦答案

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

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 - 這種擔憂是......瘋狂.加載 null 可以說是稍微更便宜,但如果您不小心檢查值,可能會導致空引用異常.

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.

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

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 級別,"" 和 Empty 之間的區(qū)別只是 ldstr 與 ldsfld - 但兩者都給出了相同的單個內(nèi)部字符串引用.此外,在最近的 .NET 版本中,JIT 直接攔截了這些,產(chǎ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.你使用哪個?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(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?(覆蓋 == 運算符.如何與空值進行比較?)
What does the question mark in member access mean in C#?(成員訪問中的問號在 C# 中是什么意思?)
The || (or) Operator in Linq with C#(||(或)C# 中的 Linq 運算符)
C# null coalescing operator equivalent for c++(C# 空合并運算符等效于 C++)
主站蜘蛛池模板: 亚洲一区久久 | 一区二区三区四区在线免费观看 | 一级a性色生活片久久毛片 午夜精品在线观看 | 久草网址| 99热激情| 欧美一级在线观看 | 国产成人精品久久二区二区91 | 精品久久久久久 | 亚洲国产精品一区二区第一页 | 中文字幕 欧美 日韩 | 亚洲人成在线播放 | 秋霞国产 | 欧美一区免费 | 蜜桃在线一区二区三区 | 一区二区三区久久久 | 国产探花在线精品一区二区 | 日韩精品久久一区二区三区 | 亚洲一区二区在线免费观看 | 久久av一区二区三区 | 91精品久久久久久久 | 国产精品久久久久久久久久久久 | 国产一级片91 | 久久99国产精品久久99果冻传媒 | 国产小视频在线看 | 亚洲高清在线 | 精品亚洲第一 | 久久精品成人 | 国产日韩欧美91 | av午夜电影 | 中文字幕伊人 | 欧美在线a| 成人在线播放 | 亚洲一区二区视频 | 色男人的天堂 | 日韩中文字幕在线观看 | 日本一本视频 | 成人高清视频在线观看 | 成人精品毛片 | 久久精品网 | av网站免费观看 | 精品国产乱码久久久久久闺蜜 |