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
3 answers

Cannot return null in function whose return type is generic

If I have a type, say, an int, I can make it nullable by adding a question mark to the end of it. For instance, the following code compiles: int? x = null; while the following code, with the question mark removed, does not: int x = null; //throws a…
256Bits
  • 378
  • 1
  • 13
1
vote
1 answer

Convert to Generic Nullable

i made a small timeout struct and wanted to add conversion to make it a bit easier to use: public struct TimeoutValue { public static TimeSpan DefaultTimeout { get; } = TimeSpan.FromSeconds(5); public DateTime CreationTime { get; set; }…
1
vote
2 answers

kotlin, is there a better way to check multiple nullables

In kotlin it could use ?.let to only run the code block if the variable is not null. If there are multiple variables it could be done like: v1?.let { value1 -> v2?.let { value2 -> doSomething(value1, value2) } } compare with if (v1…
lannyf
  • 9,865
  • 12
  • 70
  • 152
1
vote
0 answers

Web API Post with Null body

Hy everybody, I'm trying to understand why if I send a request from my client with a null object my Server doesn't intercept it. What I'm aiming is to handle a Post call with no object [HttpPost] [Route("Insert2")] public IActionResult…
MalVets
  • 13
  • 3
1
vote
2 answers

Dereference of a possibly null reference despite checking that the value is not null in the Linq Where() call

I have prepared a simple C# Fiddle, which calls an OSRM map matching service URL and parses the JSON response. My problem is, that there is a line producing the warning CS8602: Dereference of a possibly null reference: if (osrmResponse?.code == "Ok"…
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
1
vote
0 answers

Parameters for Numerics.IEqualityOperators Are Nullable?

With the creation of C# 11, static abstract operators are now allowed to be defined in interfaces. Because of this, the .NET Core 7 library now includes the interfaces System.Numerics.IEqualityOperators and System.Numerics.IComparisonOperators. The…
256Bits
  • 378
  • 1
  • 13
1
vote
3 answers

Is there a way to define an generic interface with a constraint that the type can be null (but cannot be a value type)?

I'd like to define an generic interface that allows nullable value types (int?, double?, etc.) and class types (which can also be null). I do not want to allow a simple value type. Is there a way to do this?
bsh152s
  • 3,178
  • 6
  • 51
  • 77
1
vote
2 answers

What @Nullable to use in Java (as of 2023/JDK21)?

As of 2023/JDK21, what @Nullable to use in Java? Many online materials, don't even mention what import should be. So it is now (dark) history in what order those annotation appeared. I hope for general answer and from a reputable source (please…
Paul Verest
  • 60,022
  • 51
  • 208
  • 332
1
vote
0 answers

Yup schema that would allow null for value when the react hook form is initialized, but would need object on submit

I have a TS NextJS13 React-Hook-Form with React-Select in Controller and Yup Resolver. Since React Hook for do not allow to use Undefined for Controller's default values, I have set it to Null. But in last version of Yup Resolver (3.1.1) your schema…
1
vote
2 answers

How do I tell the compiler that a property is not null when a certain method has been executed?

Consider this code within my base class public MyClass? Input { get; set; } protected virtual void DoSomething() { Input = new(); } Now I want to override the method and modify some properties on my Input property. protected override void…
Marvin Klein
  • 1,436
  • 10
  • 33
1
vote
2 answers

C# interface static properties require initial value when nullable is enabled?

Say I have the following interface: public interface IFoo { public int Number { get; } public string Text { get; } public static int StaticNumber { get; } public static string StaticText { get; } // Nullable warning. } Normally,…
Tuckertcs
  • 29
  • 5
1
vote
1 answer

take nullable and return non-nullable reference and value types in single method

i want a method that takes a nullable and returns nonnullable. it can be value or ref type. i only seem to be able to do this by having2 methods: public static T Do( T? t ) where T: struct { return t == null ? throw…
Chris DaMour
  • 3,650
  • 28
  • 37
1
vote
0 answers

Is there a built-in function to query a type hint for optionality/"None-ability" in Python 3.10 or later?

Is there a function in the standard library to query whether the type hint for a field admits the None value? For example, it would return True for foo, bar, baz, and False for x, in class A below: from dataclasses import dataclass from typing…
Ross Bencina
  • 3,822
  • 1
  • 19
  • 33
1
vote
0 answers

Nullable Value Types as Members in a Struct: What are the Implications Memory-Wise?

I'm new to StackOverflow so sorry if anything about this post is weird or poorly formatted, giving it my best here, I'm also infamously bad with programming linguo so I might sound incredibly dumb as I say all this. Anyway, onto my question: My…
1
vote
2 answers

How to tell VS that member is not null

I have a class that is like class Operation { private int? opA = null; private int? opB = null; private Func? opFunc = null; public void SetOperandA(int value) => opA = value; public…
user137794
  • 1,636
  • 2
  • 10
  • 11