07
“Cleaning” my script I found that I wrote both
Sanderling?.MemoryMeasurementParsed?.Value?.blabla...
and sometimes
Sanderling.MemoryMeasurementParsed?.Value?.blabla...
Both of the 2 syntaxes are working very well, so I wondered if there is a strong difference between them…?
1 Like
?. is used to ask in data structures, . is used to access directly.
For example Sanderling.waitmeasurements () is correct, because anytime the function is there.
but to descend into structure to blabla, is better to ask , because the structure can be null ( you dont have the value there , or you are between dock/undock)
Tests the value of the left-hand operand for null before performing a member access ( ?.
) or index ( ?[]
) operation; returns null
if the left-hand operand evaluates to null
.
These operators help you write less code to handle null checks, especially for descending into data structures.
next, the “.”
Use .
to form a qualified name to access a type within a namespace, as the following code shows:
System.Collections.Generic.IEnumerable<int> numbers = new int[] { 1, 2, 3 };
Use the using
directive to make the use of qualified names optional.
- Use
.
to access type members, static and non-static, as the following code shows:
var constants = new List<double>();
constants.Add(Math.PI);
constants.Add(Math.E);
more about operators
Thanks, I didn’t find that microsoft page when I made my researchs…
1 Like
? is used for nullable elements, means you’ll receive NULL if something is NULL instead of FALSE in case of just .
and you can’t use ? on elements which are not nullable … but in general it’s doing almost the same