var a = b? .cd;
Should this expression always give a compilation error? If b is null, the null value propagates through so that c will also be null and therefore also needs this operator. In my understanding, the use of this operator in an expression is viral.
But neither Visual Studio 2015 nor Resharper tell me anything, did I miss something here?
To do this, simply the syntactic sugar operator:
MyType a = b == null ? null: b.c.d;
Why this should cause a compilation error is not clear to me.
b , , c , ,
. , b null c, , , . null c d .
b
c
null
d
null b null.
var a = b == null ? null : b.c.d
, -, ?. , null, null, , , , b b.c == null, var a = b?.c?.d.
?.
b.c == null
var a = b?.c?.d
, :
var a1 = b?.c.d;
:
var a2 = (b?.c).d;
, ?. (, !). , "" "" , ?. null.
, a1 , d ( Nullable<> , ), b . b null, , b.c.d, , b.c null.
a1
Nullable<>
b.c.d
b.c
a2 . , b null, (b?.c) , . NullReferenceException. ( , c .)
a2
(b?.c)
.
NullReferenceException
, " ", b?.c.d (b?.c).d!
b?.c.d
(b?.c).d
# ; Null- ยง 7.7.1.
Source: https://habr.com/ru/post/1673717/More articles:How to make StrToInt, StrToIntDef ignore hexadecimal values? - delphiLucen from memory - javagroovy upload yaml file, modify and write it to file - yamlPerfectSwift: Unable to compile PerfectCrypto - ubuntuhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1673716/should-i-be-writing-logs-to-console-in-production&usg=ALkJrhhB6fl5S8VtFYk-DiOE90ipZmdwVgRead the YAML file in Groovy - yamlImmediate stream read in a channel in a recordable stream - javascriptmatching the occurrence of the opposite number in a python list - pythonC # Json.NET Render Flags Enum as String Array - jsonMemory leak tracking in Vue.js server side? - javascriptAll Articles