简体   繁体   English

可空操作员。?

[英]Nullable operator .?

I recall I read this somewhere but am not able to find it in Google results now. 我记得我在某个地方看过这个,但现在无法在谷歌搜索结果中找到它。

Does the newest C# (VS2013) support any such operator? 最新的C#(VS2013)是否支持任何此类运营商?

SomeObject.?SomeMember = SomeValue;

This is supposed to assign SomeValue to SomeObject.SomeMember only if SomeObject is not null. 这应该分配SomeValueSomeObject.SomeMember只有SomeObject不为空。

NB: I know we can do this through HasValue and other ways. 注意:我知道我们可以通过HasValue和其他方式来做到这一点。 I'm just asking about the new operator. 我只是询问新的运营商。

Well it has nothing to do with Nullable types.It's null propagation operator and will work for each type that can be null, not just for Nullable<T> , reference types as well. 它与Nullable类型无关。它是null传播运算符 ,适用于每个可以为null的类型,不仅适用于Nullable<T> ,也适用于引用类型。

Does the newest C# (VS2013) support any such operator? 最新的C#(VS2013)是否支持任何此类运营商?

You could install Roslyn end user preview if you are using VS 2013, or Visual Studio 14 CTP 3 如果您使用的是VS 2013或Visual Studio 14 CTP 3,则可以安装Roslyn最终用户预览

It is available in the Roslyn compiler and it's called Null-propagation - it's already implemented. 它在Roslyn编译器中可用,它被称为Null-propagation - 它已经实现了。 Roslyn compiler will be available in VS 14 by default. 默认情况下,Roslyn编译器将在VS 14中提供。

No, Visual Studio 2013 does not support such operator. 不,Visual Studio 2013不支持此类运算符。 Not out of the box at least. 至少没有开箱即用。

If you want to use the null propagation operator , or any other C# 6 feature , you will have to install and use the CTP of Roslyn . 如果要使用空传播运算符或任何其他C#6功能 ,则必须安装并使用Roslyn的CTP。 Roslyn will be the default compile of Visual studio "14" though (we don't know its definitive name yet). Roslyn将是Visual Studio“14”的默认编译(我们还不知道它的确定名称)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM