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

使用空合并運(yùn)算符的獨(dú)特方法

Unique ways to use the null coalescing operator(使用空合并運(yùn)算符的獨(dú)特方法)
本文介紹了使用空合并運(yùn)算符的獨(dú)特方法的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我知道在 C# 中使用 null 合并運(yùn)算符的標(biāo)準(zhǔn)方法是設(shè)置默認(rèn)值值.

I know the standard way of using the null coalescing operator in C# is to set default values.

string nobody = null;
string somebody = "Bob Saget";
string anybody = "";

anybody = nobody   ?? "Mr. T"; // Returns Mr. T
anybody = somebody ?? "Mr. T"; // Returns "Bob Saget"

但是??還能用來(lái)做什么?除了更簡(jiǎn)潔和更容易閱讀:

But what else can ?? be used for? It doesn't seem as useful as the ternary operator, apart from being more concise and easier to read than:

nobody = null;
anybody = nobody == null ? "Bob Saget" : nobody; // Returns Bob Saget

因此,很少有人知道空合并運(yùn)算符...

So given that fewer even know about null coalescing operator...

  • 您是否將 ?? 用于其他用途?

?? 是必需的,還是應(yīng)該使用三元運(yùn)算符(即大多數(shù)都熟悉)

Is ?? necessary, or should you just use the ternary operator (that most are familiar with)

推薦答案

嗯,首先,它比標(biāo)準(zhǔn)的三元運(yùn)算符更容易鏈接:

Well, first of all, it's much easier to chain than the standard ternary operator:

string anybody = parm1 ?? localDefault ?? globalDefault;

對(duì)比

string anyboby = (parm1 != null) ? parm1
               : ((localDefault != null) ? localDefault
               : globalDefault);

如果可能為 null 的對(duì)象不是變量,它也能很好地工作:

It also works well if a null-possible object isn't a variable:

string anybody = Parameters["Name"]
              ?? Settings["Name"]
              ?? GlobalSetting["Name"];

對(duì)比

string anybody = (Parameters["Name"] != null ? Parameters["Name"]
                 : (Settings["Name"] != null) ? Settings["Name"]
                 :  GlobalSetting["Name"];

這篇關(guān)于使用空合并運(yùn)算符的獨(dú)特方法的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(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#?(成員訪問(wèn)中的問(wèn)號(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++)
主站蜘蛛池模板: 久久午夜精品福利一区二区 | 日韩一级免费电影 | 国产一区二区三区免费观看在线 | 久在草 | 日日干夜夜操 | 蜜桃av一区二区三区 | 亚洲国产精品一区二区久久 | 国产一二区视频 | 中文字幕一区二区三区在线观看 | 一级特黄视频 | 成人精品在线视频 | 国产日韩欧美二区 | 成人午夜免费在线视频 | 亚洲电影专区 | 怡红院怡春院一级毛片 | 日韩高清一区二区 | 特一级毛片 | 欧美三级电影在线播放 | 中文字幕亚洲精品在线观看 | 九九导航 | 国产福利视频在线观看 | 欧美一级片中文字幕 | 中文字幕第一页在线 | 99精品国产成人一区二区 | 日韩免费视频一区二区 | 亚洲精品久久久久久宅男 | 91久久| 伊人伊成久久人综合网站 | 久久成人精品视频 | 三级视频网站 | 中文字幕在线中文 | 国产精品亚洲欧美日韩一区在线 | 亚洲天堂999 | 精品一区二区视频 | 日本精品一区二区三区视频 | 日韩欧美精品在线播放 | 亚洲精品在线视频 | 日韩欧美中文 | 国产高清视频 | 一区二区三区精品 | 日韩精品一区二区三区高清免费 |