在C#中,成员访问中的问号是什么意思? [英] What does the question mark in member access mean in C#?

查看:115
本文介绍了在C#中,成员访问中的问号是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释以下代码中的成员访问权限中的问号是什么意思吗?

Can someone please explain to me what does the question mark in the member access in the following code means?

它是标准C#的一部分吗?尝试在Xamarin Studio中编译此文件时出现解析错误.

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

推荐答案

它是 C#6 中引入的> Null Propagation运算符 ,仅当对象this.AnalyzerLoadFailed不为null时,它将调用该方法:

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 –空传播运营商 ,您还可以在>在此处

我也曾经在c#6中写过关于此即将推出的功能的信息 此处

i also once wrote about this upcoming feature in c# 6 here

这篇关于在C#中,成员访问中的问号是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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