null-coalescing-operator Questions
7
Solved
If I have code similar to the following:
while(myDataReader.Read())
{
myObject.intVal = Convert.ToInt32(myDataReader["mycolumn"] ?? 0);
}
It throws the error:
Object cannot be cast from DBNu...
Limestone asked 24/2, 2012 at 19:29
6
Solved
Is there any shorthand in c# now that will cutdown the following code:
var testVar1 = checkObject();
if (testVar1 != null)
{
testVar2 = testVar1;
}
In this situation only want to assign testVar...
Skepticism asked 6/6, 2019 at 21:58
16
Solved
In C# there's a null-coalescing operator (written as ??) that allows for easy (short) null checking during assignment:
string s = null;
var other = s ?? "some default value";
Is there a python e...
Diagonal asked 12/2, 2011 at 15:4
5
Solved
Is it possible to implement the ?? operator in Ruby?
a = nil
b = 1
x = a ?? b # x should == 1
x = b ?? 2 # x should == 1
Improvise asked 4/6, 2009 at 21:28
2
Solved
I am trying to use the null-coalescing operator in a C# script in Unity, my project Scripting Runtime is set to .NET 4.x so it should work correctly.
The problem is that even though the LEFT opera...
Keeling asked 3/7, 2019 at 18:1
10
Solved
Is there a C++ equivalent for C# null coalescing operator? I am doing too many null checks in my code. So was looking for a way to reduce the amount of null code.
Faceharden asked 23/11, 2009 at 19:31
16
Solved
Is there a null coalescing operator in powershell?
I'd like to be able to do these c# commands in powershell:
var s = myval ?? "new value";
var x = myval == null ? "" : otherval;
Quinlan asked 16/5, 2012 at 17:49
3
Solved
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 around it with the null-coalesce operator...
Apocynthion asked 30/4, 2013 at 17:18
2
Solved
Is there a way to do an assignment only if the assigned value is not None, and otherwise do nothing?
Of course we can do:
x = get_value() if get_value() is not None
but this will read the value...
Owl asked 17/1, 2020 at 1:33
4
Solved
Or how do I make this thing work?
I have an Interval object:
class Interval(Base):
__tablename__ = 'intervals'
id = Column(Integer, primary_key=True)
start = Column(DateTime)
end = Column(Dat...
Hyatt asked 7/8, 2013 at 11:23
19
Solved
Is there a null coalescing operator in Javascript?
For example, in C#, I can do this:
String someString = null;
var whatIWant = someString ?? "Cookies!";
The best approximation I can figure out...
Wry asked 24/1, 2009 at 18:18
3
I'm encountering some strange behavior.
When running this piece of code:
var foo = await actionContext.RequestContext?.Principal?.ToUserTokenAsync() ?? UserToken.UnidentifiedUser;
Principal is ...
Excurrent asked 3/6, 2019 at 12:37
2
I'm looking for a way to do undefined coalescing in javascript with booleans. I'm used to doing the following, for, say, positive integers:
var x = i1 || i2 || i3 || i4;
This is a 'slick' way, b...
Jelly asked 25/11, 2015 at 21:46
2
Solved
Php 8.0 introduced the nullsafe operator which can be used like so $foo?->bar?->baz;.
I have a code sample running on php 8.1 that throws the error Undefined property: stdClass::$first_name e...
Shurwood asked 12/4, 2022 at 16:13
10
Solved
Many programming languages have a coalesce function (returns the first non-NULL value, example). PHP, sadly in 2009, does not.
What would be a good way to implement one in PHP until PHP itself get...
Rules asked 18/6, 2009 at 15:49
5
Solved
Say I have this:
$username = (string) $inputs['username'] ?? null;
If $inputs['username'] is set then I want it to cast to string. If it's not set then $username should be null.
However, at the...
Jacobean asked 14/5, 2018 at 20:26
12
Solved
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:
s.SiteNumber.IsNullOrEmpty() ? "No Number" : s.SiteNum...
Pow asked 10/3, 2010 at 20:1
3
Solved
I have recently found a problem with the null-coalescing operator while using Json.NET to parse JSON as dynamic objects. Suppose this is my dynamic object:
string json = "{ \"phones\": { \"persona...
Dm asked 14/3, 2015 at 17:0
14
Solved
Can someone explain the differences between ternary operator shorthand (?:) and null coalescing operator (??) in PHP?
When do they behave differently and when in the same way (if that even happens)...
Matador asked 2/1, 2016 at 22:23
7
Solved
I'm tempted to lie and say that English is my second language, but the truth is that I just have no idea what 'Coalescing' means. I know what ?? 'does' in C#, but the name doesn't make sense to me....
Lyontine asked 20/4, 2009 at 21:31
4
Solved
I'm trying to safely check if an IList<> is not empty.
var Foo = Bar.GimmeIListT(); // Returns an IList<SomeObject>
if (Foo?.Any())
// Do cool stuff with items in Foo
But there is a...
Clinandrium asked 18/7, 2017 at 10:5
4
What is the equivalent of null coalescing operator (??) in angular 2?
In C# we can perform this operation:
string str = name ?? FirstName ?? "First Name is null";
Dreiser asked 8/4, 2017 at 18:14
18
Solved
Ran across this line of code:
FormsAuth = formsAuth ?? new FormsAuthenticationWrapper();
What do the two question marks mean, is it some kind of ternary operator?
It's hard to look up in Google....
Laverty asked 15/1, 2009 at 14:3
9
Solved
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 feeling there is a more concise way to do this, e.g....
Nuno asked 30/8, 2010 at 10:6
0
Using Visual Studio 2019 with ReSharper (both on the latest version) I an unable to get intellisense to stop complaining about ECMAScript 2020 features like the null-coalescing operator (??).
The c...
Urrutia asked 20/9, 2020 at 15:45
1 Next >
© 2022 - 2025 — McMap. All rights reserved.