Questions tagged [null-coalescing]
The concept of setting a default value if a condition evaluates to null.
null-coalescing
71
questions
1
vote
1
answer
108
views
Confused with Postgres COALESCE retuning 'null'
A postgres table contains a column with the data type:
test_score character varying(10)
The column may contain null values or numeric.
SQL
Result
select COALESCE( test_score, '0' )
'' (blank)
...
0
votes
1
answer
109
views
SwiftUI error Value of optional type 'UIImage?' must be unwrapped to a value of type 'UIImage'
I'm trying to show a placeholder image in the case there has not been a picture made:
// Function to create a photo button and image placeholder
func photoButton(title: String) -> some View {
...
3
votes
2
answers
76
views
Null-coalescing out parameter doesnt give error
This question describes a error related to using Null-coalescing, Null-conditional and out parameter:
Null-coalescing out parameter gives unexpected warning
The answer details the reasons for this ...
1
vote
2
answers
535
views
Is there a nice one-liner to provide a default if a value is None?
There is a possibility that I am searching under wrong keywords, but I can't find the answer to the question:
Is there a nice one-liner to provide a default value if the variable is NoneType?
For ...
2
votes
1
answer
1k
views
Javascript Logical OR operator in return statement of a function
I am using Vuetify, specifically the v-text-field from inside v-form. Each of these v-text-fields has a property called rules, used for validation. That property accepts an array with a bunch of ...
2
votes
3
answers
3k
views
How does the null check operator work in Dart
I'm using this repository to familiarize myself with Amazon's Cognito user system. In the file lib/screens/signup_screen.dart, starting at line 27 there is this piece of code:
TextFormField(
...
0
votes
2
answers
146
views
assigned null value in Null-coalescing assignmen C#
If the phrase ?? = in C # is for assigning null then why is the value assigned in this example?
IList<string> list = new List<string>() {"cat" , "book" };
(list ??= new List<string&...
0
votes
1
answer
28
views
Check if an a propery of an object from an array is contained in another array of object
Let's say I have these arrays of object
selectedNames = [
{label: 'Nicolas', value:'Nicolas'},
{label: 'Michael', value:'Michael'},
{label: 'Sean', value:'Sean'},
{label: 'George', value:'...
0
votes
2
answers
563
views
Using c# NULL coalescing operator with NOT NULL Scenarios
I am populating a Class using LINQ and LinkUrl is a string property of my class.I need to set a value only if a property is not null , other wise no need to assign any values
Currently The conditional ...
0
votes
0
answers
37
views
Why does (Guid?)null ?? default return empty guid [duplicate]
Output from VS Immediate Window
default(Guid?)
=> null
(Guid?)null == default
=> true
(Guid?)null ?? default
=> {00000000-0000-0000-0000-000000000000}
I expected the last to be null and not ...
1
vote
3
answers
283
views
How to print the null values if the dictionary has it using LINQ
I have dictionary with the following keys and values. I am trying to print the dictionary, but nothing prints where there is a null value. How do I print "null" in the output?
Dictionary<...
1
vote
2
answers
50
views
Null coalescing string and conditional string via logical OR-operator results in number
Null coalescing by ORing a string (via PRIORITIES[NUM_TO_PRIORITY[priorityNum]] where priorityNum is input) and a string (via conditional Object.values(PRIORITIES).includes(priorityNum) ? priorityNum :...
14
votes
1
answer
8k
views
None propagation in Python chained attribute access [duplicate]
Is there a null propagation operator ("null-aware member access" operator) in Python so I could write something like
var = object?.children?.grandchildren?.property
as in C#, VB.NET and TypeScript, ...
89
votes
3
answers
8k
views
What is the ?[]? syntax in C#?
While I was studying the delegate which is actually an abstract class in Delegate.cs, I saw the following method in which I don't understand
Why the return value uses ? though it's already a ...
0
votes
2
answers
78
views
Is the c# coalescence the same as an if statement when setting to null?
Are these two statements the same?
if (dep.BirthDate.HasValue) {
myObj.GetType().GetProperty("birthdate").SetValue(myObj, (DateTime)dep.BirthDate, null);
}
myObj.GetType().GetProperty("birthdate")....