tagged [null-coalescing-operator]
Is there a more elegant way to add nullable ints?
Is there a more elegant way to add nullable ints? I need to add numerous variables of type nullable int. I used the null coalescing operator to get it down to one variable per line, but I have a feeli...
- Modified
- 30 Aug at 10:6
?? Coalesce for empty string?
?? Coalesce for empty string? Something I find myself doing more and more is checking a string for empty (as in `""` or null) and a conditional operator. A current example: This is just an extension m...
- Modified
- 20 Jun at 08:7
Unique ways to use the null coalescing operator
Unique ways to use the null coalescing operator I know the standard way of using the [null coalescing operator](https://en.wikipedia.org/wiki/Null_coalescing_operator) in C# is to set default values. ...
- Modified
- 13 Nov at 13:29
Is there an "opposite" to the null coalescing operator? (…in any language?)
Is there an "opposite" to the null coalescing operator? (…in any language?) null coalescing translates roughly to `return x, unless it is null, in which case return y` I often need `return null if x i...
- Modified
- 20 Jun at 09:12
Null-coalescing operator returning null for properties of dynamic objects
Null-coalescing operator returning null for properties of dynamic objects I have recently found a problem with the null-coalescing operator while using Json.NET to parse JSON as dynamic objects. Suppo...
- Modified
- 14 Mar at 20:27
How to cast a nullable DateTime to UTC DateTime
How to cast a nullable DateTime to UTC DateTime I'm reading back a DateTime? value from my view. Now I check to see if the `NextUpdate` DateTime? `HasValue` and if so convert that time to `UTC`. From ...
- Modified
- 2 Jun at 10:32
Null coalescing operator IList, Array, Enumerable.Empty in foreach
Null coalescing operator IList, Array, Enumerable.Empty in foreach In [this question](https://stackoverflow.com/questions/3088147/why-does-net-foreach-loop-throw-nullrefexception-when-collection-is-nu...
- Modified
- 18 Sep at 11:14
How to null coalesce for Boolean condition?
How to null coalesce for Boolean condition? I'm trying to safely check if an `IList` is not empty. But there is an error with the condition: > Cannot implicitly convert 'bool?' to 'bool'. An explicit ...
- Modified
- 18 Jul at 10:5
An expression tree lambda may not contain a null propagating operator
An expression tree lambda may not contain a null propagating operator The line `price = co?.price ?? 0,` in the following code gives me the above error, but if I remove `?` from `co.?` it works fine. ...
- Modified
- 21 Oct at 13:47
Any good reasons to not use null-coalescing operator for lazy initialization?
Any good reasons to not use null-coalescing operator for lazy initialization? Greetings I was doing some lazy initialization code today, and thought why not use the null-coalescing operator to do this...
- Modified
- 13 Sep at 21:29
What is the proper way to check for null values?
What is the proper way to check for null values? I love the null-coalescing operator because it makes it easy to assign a default value for nullable types. That's great, except if I need to do somethi...
- Modified
- 20 Mar at 14:11
C# Reflection get Field or Property by Name
C# Reflection get Field or Property by Name Is there a way to supply a name to a function that then returns the value of either the field or property on a given object with that name? I tried to work ...
- Modified
- 4 Jul at 13:11
using coalescing null operator on nullable types changes implicit type
using coalescing null operator on nullable types changes implicit type I would expect the next three lines of code to be the same: ``` public static void TestVarCoalescing(DateTime? nullableDateTime) ...
- Modified
- 16 Apr at 08:7
Why doesn't the null coalescing operator (??) work in this situation?
Why doesn't the null coalescing operator (??) work in this situation? I'm getting an unexpected `NullReferenceException` when I run this code, omitting the `fileSystemHelper` parameter (and therefore ...
- Modified
- 19 Dec at 06:50
Is the null coalescing operator (??) in C# thread-safe?
Is the null coalescing operator (??) in C# thread-safe? Is there a race condition in the following code that could result in a `NullReferenceException`? -- or -- Is it possible for the `Callback` vari...
- Modified
- 14 May at 18:45
Curious null-coalescing operator custom implicit conversion behaviour
Curious null-coalescing operator custom implicit conversion behaviour [Roslyn](https://github.com/dotnet/roslyn) This question arose when writing my answer to [this one](https://stackoverflow.com/ques...
- Modified
- 23 May at 12:18