Questions tagged [null]
This tag should be used for questions where you are handling null variables or values.
160 questions
4 votes
3 answers
165 views
Calculate length of continuous gaps
I have a list with some nan values, out of which some are continuous, e.g.: list = [1, 2, 3, np.nan, np.nan, 6, 7, np.nan, 9, np.nan,np.nan,np.nan, 12] For some ...
10 votes
3 answers
6k views
Filter out nulls from sequence of nullables to produce sequence of non-nullables
While introducing nullable reference types to our enterprise application's codebase, I found that we are often using LINQ on sequences of nullable reference types where we filter out the nulls using <...
3 votes
1 answer
1k views
Setting all class members to null to destroy strong references
At work we are using Xamarin.iOS for our apps. We frequently have to fight it's disadvantages, namely it's memory leak issues where strong cyclic references keep objects alive and prevent them from ...
0 votes
1 answer
114 views
Android APP User class implementation
This is a follow-up question for Android app class serialization. The implementation of User class has been updated and the functionality of null string checking, ...
2 votes
1 answer
192 views
Conventional C# for LinkedList with (non-)nullable references + xunit tests
I'm new to C# and would appreciate any feedback you might have on the following doubly-linked list implementation, particularly WRT the following language features: Exception handling Debug.Assert ...
9 votes
3 answers
3k views
Error solution: Uncaught TypeError
Uncaught TypeError: document.getElementById(...) is null I have a single JavaScript file that is connected to multiple pages. The below snippet is a function that is used for a single page. The above ...
14 votes
6 answers
3k views
C# consecutive and redundant null checks
I am working on a C# application and I want to support multiple themes, so I wrote a ThemeManager class that can check, load and apply a specific theme. A theme is ...
2 votes
0 answers
378 views
Extension method: Task<T>.CoalesceAwait
There has been ongoing concern about the question of awaiting a task that could possibly be null, as when using null-coalescing operators. Consider the following: ...
3 votes
1 answer
117 views
Non-nullable reference type default parameters in C# 8
I was working to upgrade some code to C# 8.0 and came across an interesting pattern with default parameters and non-nullable reference types. I'm working if it's clear enough to the caller. Given ...
-2 votes
1 answer
144 views
How to get rid of many if null checks - c# [closed]
How could I refactor this code to get it more cleaner: ...
6 votes
5 answers
446 views
Simplify & Reduce steps in the IsDistinct function
Because I often have to deal with two Variants that may or may not be Null, we need a null-safe equality test, so I came up with ...
6 votes
2 answers
21k views
handle null in Comparator class
I have a class LoanAccount that contains an attributes creationDate and loanAmount. I ...
2 votes
3 answers
2k views
String whitespaces
Here is a shortest possible syntax for replacing whitespaces with null and throwing an exception where it is not allowed: ...
5 votes
2 answers
840 views
Multiple null Checks or try/catch NullPointerException [closed]
There is A LOT of information online stating that you should NEVER catch a NullPointerException. Generally I agree, but I am wondering about this one case. I have inherited code that requires me to ...
6 votes
4 answers
3k views
Handling Null values (and equivalents) routinely in Python
I've found the following code invaluable in helping me 'handle' None values including "whitespace" characters that should be treated as None based on the situation. I have been using this code for ...