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

ComboBox with enumeration and null value

I have a ComboBox that is filled from the values of an enumeration: That uses…
juergen d
  • 201,996
  • 37
  • 293
  • 362
1
vote
1 answer

Inferred type is Collection of nullables but expected Collection of non-nullables

I intended to process some data (it's a list of parsed from json objects Nuu, in the example below I just stubbed the list). To process that collection I pass a consumer println into the method getAllNuu that retrieves and parses that…
exenza
  • 966
  • 10
  • 21
1
vote
1 answer

Invalid cast from System.Int32 to Nullable in case of Enum properties

I have the following static method: public static cols Parse(string[] inCols, int[] dat) { cols c = new cols(); PropertyInfo[] properties = typeof(cols).GetProperties(); for (int i = 0; i < inCols.Length; i++) { …
Gabor Varga
  • 95
  • 1
  • 11
1
vote
1 answer

Kotlin Nullable JNI Type

How to work with Kotlin nullable type like 'Long?', 'String?' etc. on JNI? JNI type signatures represent the following information: Signature |Java Type -----------|---------------- Z | boolean B | byte C | char S …
Anonimys
  • 596
  • 1
  • 5
  • 14
1
vote
1 answer

Weird PostgreSQL null check behavior for custom types

I am trying to create a function which should map the table row to my custom type and return that as a result. If some column in that table is NULL, then IS NOT NULL check on my custom type does not work! Check the example: I have a simple custom…
elBastarde
  • 185
  • 3
  • 8
1
vote
0 answers

C# 8.0 Nullable, How to indicate method checks for null

Say I have a method that starts like this, where we use a method to check for null and other validations. If I do that, the compiler still complains about a possible null reference exception in the lines of code that follow. Is there a way to make…
Ristogod
  • 905
  • 4
  • 14
  • 29
1
vote
1 answer

Why does the `System.Nullable` type has the `StructLayout(LayoutKind.Sequential)` attribute?

Why does the System.Nullable type has the StructLayout(LayoutKind.Sequential) attribute? I found the following piece of text and code in the CLR via C# book: Here is the logical representation of how the System.Nullable type is…
qqqqqqq
  • 1,831
  • 1
  • 18
  • 48
1
vote
0 answers

Same method signature confusion

Assuming C# 8.0 and reference type nullability, why are these signatures considered equal: void Test(IEnumerable enumerable) where T : class void Test(IEnumerable enumerable) where T : struct but these are not? void…
Krzaku
  • 186
  • 4
  • 16
1
vote
1 answer

Unexpected non-null type in pure Java API

Gradle provides the following class in its API: https://docs.gradle.org/5.6.4/javadoc/org/gradle/api/tasks/ScalaRuntime.html This class has a simple constructor which accepts a Project instance. However, in my case I don't have a Project on hand,…
Vladimir Matveev
  • 120,085
  • 34
  • 287
  • 296
1
vote
2 answers

Laravel: How can I validate two optional date fields using the before and after validation rules

I'm trying to validate the date fields so that active_from needs to be a date before active_until and active_until needs to be a date after active_from. Both fields are hidden and disabled until the user selects Yes on a select field called…
Edd
  • 11
  • 3
1
vote
2 answers

unwrap T from Nullable

Wanted a simple but efficient method to get value from Nullable when T is not known at the compile time. So far have something like this: public static object UnwrapNullable(object o) { if (o == null) return null; if…
Ilia G
  • 10,043
  • 2
  • 40
  • 59
1
vote
3 answers

Typescript - assign null to variable

I have a class like this: export class Signal { method: (d: any) => void; otherMethod: (d: any) => void; public resetMethods(): void { this.method = null; this.otherMethod = null; } } unfortunately this will not…
Plastic
  • 9,874
  • 6
  • 32
  • 53
1
vote
2 answers

Compounded Null Checking With Non-Nullable Parameter

I've been looking through some MS reference material for an upcoming exam and have found a supposedly previous question where I disagree with the answer. Upon consideration, I'm going to post a screenshot of the question rather than condense the…
James
  • 356
  • 2
  • 13
1
vote
2 answers

How can I make mandatory for a derived class to have all basic data-type properties to be of Nullable types?

How can I make mandatory for a derived class to have all basic data-type properties to be of Nullable types? That is, the derived class must have all basic data type properties of nullable types.
user366312
  • 16,949
  • 65
  • 235
  • 452
1
vote
1 answer

Linq to SQL to map a nullable bool value to IsNull and not = NULL

I'm trying to use Linq to SQL to filter a table with a nullable bool value based on a variable. But if the variable's value is NULL, LINQ seems to translate the query to Field = NULL instead of Field IS NULL. Based on other posts I've seen to use…
Cameron Castillo
  • 2,712
  • 10
  • 47
  • 77