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
16
votes
2 answers

Is it possible to write nonnull-annotation in init?

Now in objective-c there are two new annotations: nonnull and nullable. Which of them should I use for return type specification of init method? - (instancetype)init { if (self = [super init]) { // ... } } Voice for nullable: There…
Mikhail
  • 1,061
  • 2
  • 13
  • 30
16
votes
2 answers

Nullability issue on Xcode 6.3

I upgraded to Xcode 6.3 yesterday. Since then, I have been unable to build anything that has Parse.framework in it. For PFConstants.h I get errors like nullability specifier '_nullable' cannot be applied to non-pointer I have never seen this error…
user717452
  • 33
  • 14
  • 73
  • 149
16
votes
7 answers

C# - Basic question: What is '?'?

I'm wondering what ? means in C# ? I'm seeing things like: DateTime? or int?. I suppose this is specific to C# 4.0? I can't look for it in Google because I don't know the name of this thing. The problem is I'm using DateTime and I have a lot of cast…
Amokrane Chentir
  • 29,907
  • 37
  • 114
  • 158
16
votes
3 answers

WPF Textbox accept INT but not NULLABLE INT?

Model public int? SizeLength { get; set; } XAML Once user try to backspace or delete the value in this textbox, a message Value '' cannot be converted. May I know what's…
SuicideSheep
  • 5,260
  • 19
  • 64
  • 117
16
votes
10 answers

Check inside method whether some optional argument was passed

How do I check if an optional argument was passed to a method? public void ExampleMethod(int required, string optionalstr = "default string", int optionalint = 10) { if (optionalint was passed) return; } Another approach is to use…
Yariv
  • 12,945
  • 19
  • 54
  • 75
16
votes
9 answers

testing inequality with columns that can be null

So, I asked a question this morning, which I did not phrase correctly, so I got a lot of responses as to why NULL compared to anything will give NULL/FALSE. My actual question was, what is the time honored fashion in which db guys test inequalities…
rouble
  • 16,364
  • 16
  • 107
  • 102
16
votes
2 answers

The type 'T' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable'

Why am I getting this error in the following code? void Main() { int? a = 1; int? b = AddOne(1); a.Dump(); } static Nullable AddOne(Nullable nullable) { return ApplyFunction(nullable, (int x) => x + 1); } static…
Clive
  • 1,128
  • 2
  • 11
  • 19
16
votes
2 answers

C# Nullable arrays

I have a search function, but I would like LocationID to be an array of integers rather than just a single integer. I'm not sure how to do this since I want it to also be nullable. I've looked at doing int?[] but then I'd have to check the…
Preston
  • 1,300
  • 1
  • 17
  • 32
15
votes
5 answers

Why does the == operator work for Nullable when == is not defined?

I was just looking at this answer, which contains the code for Nullable from .NET Reflector, and I noticed two things: An explicit conversion is required when going from Nullable to T. The == operator is not defined. Given these two facts,…
devuxer
  • 41,681
  • 47
  • 180
  • 292
15
votes
6 answers

Alternatives to nullable types in C#

I am writing algorithms that work on series of numeric data, where sometimes, a value in the series needs to be null. However, because this application is performance critical, I have avoided the use of nullable types. I have perf tested the…
Ryan
  • 1,621
  • 2
  • 13
  • 14
15
votes
6 answers

Explanation of int? vs int

Possible Duplicate: What's the difference between 'int?' and 'int' in C#? I've come across some code in C# that declares a variable as: int? number What does the ? mean and how does this differ from just: int
5n0u7
  • 199
  • 1
  • 3
  • 7
15
votes
3 answers

Why is it slower to compare a nullable value type to null on a generic method with no constraints?

I came across a very funny situation where comparing a nullable type to null inside a generic method is 234x slower than comparing an value type or a reference type. The code is as follows: static bool IsNull(T instance) { return instance ==…
Diego Frata
  • 1,028
  • 7
  • 15
15
votes
2 answers

Difference between Union Types with Null and Nullable Object declaration in Typescript

I recently found a bit of typescript code in a bigger angular project, that had a Bitwise-OR/Pipe-Symbol within its object declaration. Like this: dataSource: FileSource | null; In my understanding it is an object of the type FileSource that is…
Babofett
  • 182
  • 3
  • 11
15
votes
1 answer

Get field of optional object or return null

I have optional object: Optional newestDetail; I would like to return newestDetail.getId() or if newestDetail is null return null. Do we have more sophisticated approach of doing this, than following? return…
Rudziankoŭ
  • 10,681
  • 20
  • 92
  • 192
15
votes
3 answers

Define a column as nullable in System.Data.DataTable

I need to define a System.Data.DataTable in C# VS2013; in one column, it may be int or null. But I got: DataSet does not support System.Nullable<>. For the definition: public DataTable myDataTable myDataTable = new…
Lily
  • 295
  • 1
  • 4
  • 14