Questions tagged [nullable]

The nullable tag is for issues relating to nullable members or types. A null is used to represent a missing or unknown value.

A data member is nullable if it can have the special value of NULL, instead of their common range of possible values. Nullable types are a feature of some statically-typed programming languages.

.NET

In , the built-in generic type System.Nullable<T> allows the programmer to use value types like int or DateTime with a value of null. Several .NET languages have a special syntax for declaring Nullable:

  • In , int? is an alias for System.Nullable<System.Int32>
  • In , Integer? is an alias for System.Nullable(Of System.Int32)

SQL

Null is a special marker used in SQL to indicate that data value do not exist in the database. Its proper use ensures various statistical aggregate functions perform correctly.

See more on Wikipedia.

D

The typecons module in package std has a templated struct - Nullable - for wrapping values types and allowing them to appear to have a null value (as in C#). Restriction is that the type must be able to be instantiated with T var or T var = T.init, where T represents the type being used.

Related tags

2417 questions
1
vote
4 answers

How to cast a nullable date time to a date time only if it has non null value

I have these two lines of code: result.birthdateSpecified = (someData.BirthDate != null || false); result.birthdate = someData.BirthDate as DateTime; I'd like to be able to set the result.birthdate to the someDate.BirthDate, only if it exists, in a…
chuckd
  • 13,460
  • 29
  • 152
  • 331
1
vote
2 answers

Get a nullable var from a class

Let me start off by saying my Kotlin experience is limited. I am trying to get a nullable var from a class, but get a null pointer whenever I execute it. Class code: class MultiSpinner : Spinner, OnMultiChoiceClickListener, OnCancelListener { …
N Simons
  • 13
  • 2
1
vote
1 answer

Why can't I cast generic-type with null?

A similar question, but without casting the T parameter. This does not work public T GetValueG(string Query) { object value = DBNull.Value; // Read from Database which can return DBNull if (value is DBNull) return (T)null; …
deveton
  • 291
  • 4
  • 26
1
vote
1 answer

Conversion from string yyyyMMddHHmmss to type integer is not valid

I am trying to write up a system that passes its value to the front end via an MVC web service. While it's running, I keep encountering this error and I cannot get past it; I have isolated it to this line of code but I cannot see what is wrong with…
Matt Farrell
  • 191
  • 1
  • 1
  • 13
1
vote
1 answer

C# Regex.Matches and nullability issue

I'm using C# 8 with nullable enabled and now I'm having a problem with my regex loop: public static async Task?> GetOwnersAsync(LampContext context, string? ownerString) { if (string.IsNullOrWhiteSpace(ownerString)) …
Gargoyle
  • 9,590
  • 16
  • 80
  • 145
1
vote
1 answer

how to declare nullable list

i have to declare a class parameter of type nullable list(contaning String) with list default value= null data class Riga( var frase1 : List?= null ) this is raising: Property getter or setter expected One type argument expected for…
fisio
  • 494
  • 6
  • 12
1
vote
1 answer

Is it possible to make safe inline Optional in Kotlin?

In Kotlin sometimes I have to work with double nullability. For example, I need double nullability, when I want to use T? where T may be a nullable type. There are a few approaches for doing this: Holder? where Holder is data class Holder
IlyaMuravjov
  • 2,352
  • 1
  • 9
  • 27
1
vote
2 answers

How to protect code from destructuring a null value in Javascript?

I'm a big fan of destructuring and optional chaining proposal in Javascript. I couldn't help but feel that when destructuring a null or undefined value it'd be really useful if the result would be undefined as it is in optional chaining instead of…
hitchhiker
  • 1,099
  • 5
  • 19
  • 44
1
vote
1 answer

Passing nullable custom classes as paramaters

I was under the impression that if I pass a class to a function as a reference, that reference can be nullable. Example: I have a code-first entity class / database table: public class Table1 { [Key] …
Ed Landau
  • 966
  • 2
  • 11
  • 24
1
vote
2 answers

flowtype nullable object immutable property refinement

I want to use refinement for a property that can be null. This object with the checked property then passed to function as an argument. /* @flow */ const a: {+foo: ?string} = {}; const fun = (obj: {+foo: string}) => { return obj } if (a.foo) { …
iofjuupasli
  • 3,818
  • 1
  • 16
  • 17
1
vote
1 answer

WPF binding, C# Generics and nullable type result in Unhandled Exception in Visual Studio Designer

I am having a problem with the Visual Studio designer for a WPF project and the combination of binding to a type using a generic and specifying a nullable type as the generic type. I have tried to construct a minimal example of the…
1
vote
5 answers

.Any() with Nullables - Returns False When I Expect True

I have a view model with a nullable int... public ObjectViewModel (){ public int? Total } ... and there are several rows in my DB where the total is null. Despite that, this always returns false: bool exists = repo.AllRows() // renamed this for…
Scott Baker
  • 10,013
  • 17
  • 56
  • 102
1
vote
1 answer

How to deal with nullable variables that are not null?

Consider this piece of code: var foo: Foo? = null if (foo != null) { foo!!.bar() } If I omit the two !! I get this error: Smart cast to 'Foo' is impossible, because 'foo' is a mutable property that could have been changed by this time This…
user1785730
  • 3,150
  • 4
  • 27
  • 50
1
vote
4 answers

Turning on Nullable warnings in Intellij

I am setting up my Intellij environment and I am wondering how to turn on Nullable warnings for the following: Map simpleMap = new HashMap<>(); String thisWillBeNull = simpleMap.get("key"); int l = thisWillBeNull.length(); //<-- how…
Mfswiggs
  • 307
  • 1
  • 6
  • 16
1
vote
1 answer

How to use type reference nullable or how to enable it on preview in .NET Core

My problem is that i keep having the error CS8652 "C# The feature is currently in Preview and unsupported. To use Preview features, use the language version." By using "?" after the type to authorize the property to be null during a deserialization…
Luxior
  • 133
  • 1
  • 13