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

Intellisense warning disappear/appear when opening file

Two separate issues appearing; not sure if they're the same root cause or not so for now putting into one Question. I'm trying to upgrade a project to C#8 and use the nullable reference types. So, in the .csproj, I put the following into every…
Sarov
  • 545
  • 6
  • 17
1
vote
3 answers

Conditional nullable return type in kotlin

I wrote some code and that work! public fun toTimeStamp(epoch: Long?): String? = when (epoch) { null -> null else -> toTimeStamp(epoch) } public fun toTimeStamp(epoch: Long): String = …
Mohsen
  • 438
  • 5
  • 14
1
vote
1 answer

Foreign Key to one-to-all relationship

I want to build a multi-tenant solution with global and custom roles. The application's authorization will be built based on permissions. Then there may be defined a role that combines multiple permissions. I want to provide several predefined…
1
vote
0 answers

Laravel inserts `0000-00-00` instead of null when DB is set to `->nullable()` and `->default(null)`

I'm using Laravel 5.1 on a Homestead Vagrant box, PHP 7.2.14 on Ubuntu 18.04 with MySql 5.7.25. I have created a migration with this: $table->date('expiry_date')->nullable()->default(null); I have a form with a date field called expiry_date, with…
Andrew Fox
  • 794
  • 4
  • 13
  • 30
1
vote
1 answer

How to save data type "Integer" (nullable int) in Shared Preferences

What is the best way to save null value of data type "Integer" in Shared Preferences. I can find putInt(which does not allow null values); but no putInteger. Kindly suggest the proper way to achieve this.
Saqib
  • 377
  • 4
  • 7
1
vote
3 answers

C# - Converting string into nullable Guid?

Is there an easier way of converting a string into a Guid?? Just now I have this code: if (Guid.TryParse(request.QueryStringParameters["key"], out Guid result)) { whateverFunction(result); } else { whateverFunction(null); } I was hoping…
Tom Dee
  • 2,516
  • 4
  • 17
  • 25
1
vote
1 answer

Laravel allowing null dates on Model::create() but not Model->update()

I have setup my Laravel migration to allow nullable dates for my StartTime and EndTime entries as such: $table->dateTime( 'StartTime' )->nullable(); $table->dateTime( 'EndTime' )->nullable(); When I create a new entry through eloquent, it allows me…
Riples
  • 1,167
  • 2
  • 21
  • 54
1
vote
2 answers

Differentiate if an object is of type DateTime or Nullable (DateTime?)

How can I differentiate if an object is of type DateTime or NullableDateTime> (DateTime?)? I understand why the following code does not work, but can you help me with a solution that does? public void Test() { DateTime? dateTime1 =…
TheWho
  • 485
  • 3
  • 17
1
vote
1 answer

Illuminate\Database\QueryException SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed

I'm new to laravel, trying to store the data but kept getting this error: Illuminate\Database\QueryException SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: courses.user_id (SQL: insert into "courses" ("title",…
squash
  • 15
  • 4
1
vote
1 answer

VB.Net function that accepts nullables?

I wanted to make a sub that manipulated nullables. The idea is for it to take in any nullable variable, and if it has a value, then overwrite a different value. Here is what I wrote: Dim a as int? = 0 Dim b as int? = 1 Sub ApplyChange(Byref Old As…
1
vote
0 answers

Does marking a PHP parameter that defaults to NULL as nullable make any difference?

Consider the following method signature: public function foo(bool $flag = null); Versus this signature: public function foo(?bool $flag = null); Does that nullable operator make any practical difference?
Johan Fredrik Varen
  • 3,796
  • 7
  • 32
  • 42
1
vote
2 answers

what does "timespan?" mean in c#?

what does the question mark mean at the end of the variable? TimeSpan? begin = // bla bla bla The coding language is c#
Shaokan
  • 7,438
  • 15
  • 56
  • 80
1
vote
0 answers

nullable error when implementing react-native-admob in android

I have added react-native-admob in my project but when i open my project in android studio and try to run my project, i face below error react-native-admob:compileDebugJavaWithJavac…
Akhzar Nazir
  • 724
  • 9
  • 13
1
vote
1 answer

casting as "Int64" nullable integer type no longer seems to work

I can't for the life of me figure out why something that used to be so simple no longer works. Often I might map a dataframe column to a dictionary and have some null values appear as they aren't found in the dictionary keys. So the resulting column…
Armon
  • 113
  • 6
1
vote
1 answer

Entity Framework making nullable unsigned int field's value as null while saving into database

I'm having this weird problem where I try to save the value of an unsigned nullable field into a db using Entity Framework 6 and it always sets the value as NULL in Db even when I send actual values to save. I'm not sure what I'm doing wrong here. I…
Ash K
  • 1,802
  • 17
  • 44