null-coalescing Questions

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

3

Solved

Using this construct: var dict = new Dictionary<int, string>(); var result = (dict?.TryGetValue(1, out var value) ?? false) ? value : "Default"; I get an error saying CS0165 use of unassig...
Aras asked 17/3, 2019 at 12:25

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...

22

Solved

I'll explain by example: Elvis Operator (?: ) The "Elvis operator" is a shortening of Java's ternary operator. One instance of where this is handy is for returning a 'sensible default' value...
Mainis asked 7/7, 2011 at 16:30

6

Solved

I've got a database with nullable fields. When I send my values via api resource, laravel is sending null values. I want to get empty strings instead. How can I set it up? example: <?php name...
Terrill asked 29/4, 2018 at 16:12

3

Solved

When interacting with C# libraries, I find myself wanting C#'s null coalescing operator both for Nullable structs and reference types. Is it possible to approximate this in F# with a single overlo...
Contrarious asked 17/1, 2014 at 19:46

1

Solved

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 Ty...

3

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 refe...

2

Solved

How can I replace NULL with 0 in a PIVOT function on ORACLE SQL? This is the query I'm trying to write: SELECT * FROM ( SELECT DISTINCT CUSTOMER_ID AS CUSTOMER_ID, CASE WHEN CATEGORY_CODE = '...
Coenosarc asked 6/7, 2016 at 22:44

3

Solved

Python has a great syntax for null coalescing: c = a or b This sets c to a if a is not False, None, empty, or 0, otherwise c is set to b. (Yes, technically this is not null coalescing, it's mor...

2

Solved

I have properties type int? and decimal? that are being used in a calculation. If the value of any of them is null it has to default to 0. I'm trying to decide between using null-coalescing o...
Jadda asked 4/6, 2019 at 4:7

1

Solved

So, I'm aware that, in Python I can do this: variable_name = other_variable or 'something else' ...and that that will assign 'something else' to variable_name if other_variable is falsy, and oth...
Fermat asked 12/11, 2018 at 13:17

2

Solved

I was wondering why it is possible to do this in C# 7.0: int? test = 0; int test2 = test ?? throw new Exception("Error"); ..but not this: int? test = 0; int test2 = test ?? return; Can someon...
Tribute asked 14/10, 2018 at 9:18

2

Solved

Is this a compiler bug or is there a specific chosen reason why the null-conditional operator doesn't work with Func inside of generic methods? To give an example the following doesn't compile pu...
Flatware asked 13/1, 2017 at 14:39

11

How can I write a shorthand of the following scenario? get { if (_rows == null) { _rows = new List<Row>(); } return _rows; }
Failure asked 8/7, 2016 at 12:36

3

Solved

I have the following select statement to grab the next scheduled item for a stream. If there is no matching row, I want it to return a default value. Here's the SQL that I'm using: SELECT `file` FR...
Ge asked 10/3, 2013 at 5:32

4

Solved

I have 2 classes which looks like this: class Widget { string Selected { get; set; } List<Option> Options { get; set; } } class Option { string InternalCode { get; set; } string Exter...
Mintun asked 6/1, 2016 at 10:32

1

object.getProperty().getSubProperty().getSubSubProperty(); Consider the code above. An object has a property, that has a subProperty, that has a subSubProperty, that can be accessed with getter me...
Quipu asked 24/4, 2015 at 12:4

3

Solved

I have a SqlCommand object that I'm using to update a database table but it doesn't interpret my null values correctly. Here is the SQL: UPDATE dbo.tbl SET param1 = @param1, param2 = @param2, p...

2

Solved

Is there a not null coalescing operator in C# which in case could be used such as: public void Foo(string arg1) { Bar b = arg1 !?? Bar.Parse(arg1); } The following case made me think of it: p...
Kun asked 29/1, 2014 at 8:10

2

Solved

I have this table in Postgresql: CREATE TABLE my_table ( id bigint NOT NULL, value bigint, CONSTRAINT my_table_pkey PRIMARY KEY (id) ); There are ~50000 rows in my_table. The question is, wh...
Cioffi asked 21/6, 2011 at 13:53

2

Solved

I frequently face the problem to check whether an IEnumerable<T> is null before iterating over it through foreach or LINQ queries, then I often come into codes like this: var myProjection = ...
Chalybite asked 12/4, 2011 at 19:15

5

Solved

Do you think that C# will support something like ??= operator? Instead of this: if (list == null) list = new List<int>(); It might be possible to write: list ??= new List<int&g...
Guilbert asked 30/3, 2010 at 15:18

7

Solved

Possible Duplicates: ?? Null Coalescing Operator --> What does coalescing mean? What do two question marks together mean in C#? I couldn't find this question being asked here so I f...
Forwhy asked 22/10, 2009 at 15:49
1

© 2022 - 2024 — McMap. All rights reserved.