简体   繁体   中英

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?

SomeObject.?SomeMember = SomeValue;

This is supposed to assign SomeValue to SomeObject.SomeMember only if SomeObject is not null.

NB: I know we can do this through HasValue and other ways. 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.

Does the newest C# (VS2013) support any such operator?

You could install Roslyn end user preview if you are using VS 2013, or Visual Studio 14 CTP 3

It is available in the Roslyn compiler and it's called Null-propagation - it's already implemented. Roslyn compiler will be available in VS 14 by default.

No, Visual Studio 2013 does not support such operator. 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 . Roslyn will be the default compile of Visual studio "14" though (we don't know its definitive name yet).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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