本文介紹了成員訪問中的問號在 C# 中是什么意思?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
誰能給我解釋一下下面代碼中成員訪問中的問號是什么意思?
Can someone please explain to me what does the question mark in the member access in the following code means?
它是標準 C# 的一部分嗎?嘗試在 Xamarin Studio 中編譯此文件時出現(xiàn)解析錯誤.
Is it part of standard C#? I get parse errors when trying to compile this file in Xamarin Studio.
this.AnalyzerLoadFailed?.Invoke(this, new AnalyzerLoadFailureEventArgs(AnalyzerLoadFailureEventArgs.FailureErrorCode.NoAnalyzers, null, null));
AnalyzerFileReference.cs 行195
推薦答案
Null Propagation operator在C#6中引入,只有對象this.AnalyzerLoadFailed
不為null時才會調(diào)用該方法:>
It is Null Propagation operator introduced in C# 6, it will call the method only if object this.AnalyzerLoadFailed
is not null:
this.AnalyzerLoadFailed?.Invoke(this, new AnalyzerLoadFailureEventArgs(AnalyzerLoadFailureEventArgs.FailureErrorCode.NoAnalyzers, null, null));
等于:
if( this.AnalyzerLoadFailed != null)
this.AnalyzerLoadFailed.Invoke(this, new AnalyzerLoadFailureEventArgs(AnalyzerLoadFailureEventArgs.FailureErrorCode.NoAnalyzers, null, null));
參見 C# 6.0 – 空傳播運算符,您也可以在此處
我也曾經(jīng)在 c# 6 中寫過這個即將推出的特性 <強>這里
i also once wrote about this upcoming feature in c# 6 here
這篇關于成員訪問中的問號在 C# 中是什么意思?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!