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
1 answer

How to write universal generic type handling nullable values and references?

public sealed class MyClass { private T? myField; } This code compiles fine, yet when I use it with reference type (like T=string) I will get nullable myField (as expected). But when I use value type (like int) I will get…
greenoldman
  • 16,895
  • 26
  • 119
  • 185
1
vote
1 answer

Type inference for generic method differs between nullable classes and structs

In the following code, I get error CS1061 about a not found method or extension method "EmptyIfNull". using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; ImmutableDictionary? dic =…
Palec
  • 12,743
  • 8
  • 69
  • 138
1
vote
2 answers

Lombok two nullable values but one must be present

Given the following object @Getter @Builder @RequiredArgsConstructor class Example { private final String maybeA; private final String maybeB; } Is it possible to add a constraint where one of these fields has to exist? So we can have A…
user18375257
  • 151
  • 1
  • 5
1
vote
2 answers

Nullable warning in Blazor in object List and API (controller) calling

I'm new in Blazor and I'm a little bit confused about warnings and nullable. If I declare a varible like this: List result = new List(); I get a warning in here: result = await…
jos3m
  • 117
  • 1
  • 11
1
vote
3 answers

What does ?DataType mean in Vb.NET

I have the following line of code: CType(IIf(CBool(product.IsDiscontinued Is Nothing Or product.IsDiscontinued = True), False, True), Boolean?) What does the Boolean? mean at the end. I have seen it used on other data types as well.
user489041
  • 27,916
  • 55
  • 135
  • 204
1
vote
1 answer

Null check with logical operator 'and' throws error while '&&' doesn't in Kotlin

The difference between && and and and the difference between || and or: && and || use short-circuit evaluation while and and or always evaluate every condition Kotlin doc for "and" But apart from that, I get different behaviour for the following…
1
vote
0 answers

Why doesn't a non-nullable string array get treated as a non-nullable reference type?

Given the following extension method: public static void ResetToDefaults(this IList source) { for (int i = 0; i < source.Count; i++) { source[i] = default; } } The following code, in the C# nullable context, only gives me a…
Jez
  • 27,951
  • 32
  • 136
  • 233
1
vote
1 answer

Using a UDF with a REQUIRED column is creating a nullable column in my Spark Dataframe

I am trying to create a Dataframe to write to a Big Query table. One column in the Output table is a REQUIRED ID that I need to generate in my pipeline. I am doing this with the use of a UDF but no matter what I try the column is being created as…
1
vote
1 answer

Error on null properties after upgrading flutter version

can anyone solve the error of null operation in my code? I'm already changing the operator for many times and im still confusing why this still show the error, this is the highlighted error: StreamBuilder( stream:…
1988
  • 309
  • 2
  • 15
1
vote
1 answer

Writing a more refined and simplified null check c#

I have the following code, bool HasPassed= (result!= null && result.Identifier.Equals("Passed"))? true : false This works fine as it is, but I was wondering if it were possible to write this code in a better and more simplified way, maybe using the…
Dre
  • 21
  • 4
1
vote
2 answers

TypeScript 4.6.4 is indicating that this code is not valid

How do I resolve this Typescript issue? const userData: { email: string; id: string; _token: string; _tokenExpirationDate: string; } = JSON.parse(localStorage.getItem('userData')); Message from Console Error:…
software is fun
  • 7,286
  • 18
  • 71
  • 129
1
vote
0 answers

Convert a c# variable to its Nullable form using null

I'm trying to return a value of type A? from a method Value. The method returns null conditionally as I'm trying to shield the caller from obtaining a value A in some cases (without throwing exceptions): public class Container { private…
Arjun Dhawan
  • 95
  • 1
  • 5
1
vote
1 answer

Is there a way to multiply a nullable with a compact operator, something like "?*"

Is there a way to get a multiplication with a nullable using a compact syntax such as: int? i; final j = i ?* 2 ?? null; Rater than: final j = i == null ? null : i! * 2;
Stéphane de Luca
  • 12,745
  • 9
  • 57
  • 95
1
vote
0 answers

Is there a way to create a compile time warning/error when toString() is being used on nullable variables?

I work with a team that is constantly coercing String?s to Strings using toString(). I have done everything in my power to explain them that doing so is not a really good idea, but I still find that happening. Is there a plugin, or something that…
caeus
  • 3,084
  • 1
  • 22
  • 36
1
vote
3 answers

Validating Nullable fields in Java

Let's say we have a class Product which has some nullable fields that are allowed to be null, for example, quantityAvailable and quantityReserved. I may want to validate these fields and throw an error, but since they are allowed to be null, I have,…
Rosa
  • 39
  • 5