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

Nullable method-chaining with ?-Operator

I thought I can chain methods/properties on Nullable Types using the ?-Operator like so Dim foo As SomeObject? = New SomeObject() Dim bar As SomeObject? = Nothing foo?.SomeProperty 'Returns a value bar?.someProperty 'Returns Nothing However, given…
Tobi Holy
  • 85
  • 6
1
vote
1 answer

int? version available for String.IsNullOrWhiteSpace

Our application requires int? variables. I'm often checking both to make sure not null and not 0 and it does get lengthy. Is there an out of the box version of String.IsNullOrWhiteSpace() or String.IsNullOrEmpty() for int? Maybe this would require…
markokstate
  • 923
  • 2
  • 14
  • 28
1
vote
3 answers

How to ensure a boolean field to be set in Grails?

I want to ensure that one of two form fields representing a boolean value is checked. But there is no appropriate constraint to do this. nullable: false does not work. class Organisation { Boolean selfInspecting static constraints = { …
deamon
  • 89,107
  • 111
  • 320
  • 448
1
vote
4 answers

If a Sum() value returns Null use 0, currently have it casting to a nullable double?

I have a LINQ statement which is working great... its part of select here it is select new { Net = (System.Double?) ((from m0 in MOVTOS where m0.DocumentType == "NET" && m0.ClientCode == c.ClientCode group m0 by new {…
Martin
  • 23,844
  • 55
  • 201
  • 327
1
vote
1 answer

How to avoid null warning when using @NotNull and checking for null in another method before method call?

I have a bit of a complex validation system, that simplified looks something like the following: private static void mainMethod(@Nullable String startParam, @Nullable String nextParam) { String nextStep = methodSelect(startParam, nextParam); …
1
vote
3 answers

How to create a Required Field Value Object

I'm trying to create a Required Field Value Object class that will be reusable across Entities in my Domain Model. I'm still learning the C# syntax (been coding in VB.net forever). And I'm all new to DDD (but have at least read several books). My…
Scuzzlebutt
  • 494
  • 9
  • 18
1
vote
1 answer

System.Data.SqlTypes or NULLABLE native types?

If you are using a SQL Server database and you want to store null and non null values read from the database, which .NET data types are best suited, NULLABLE native types or SQLTypes? I don't care about db portability to a different db.
Chad
  • 23,658
  • 51
  • 191
  • 321
1
vote
3 answers

How to convert an int array to a nullable int array?

Let's say I have an array containing x members and I want to create another array with the same Length (x) and the same integer values: int[] arr = new int[x]; int?[] nullable_arr = arr; And I can't do this: int?[] arr = new int[x]; Is there an…
SuperMinefudge
  • 301
  • 3
  • 11
1
vote
1 answer

How to write extension methods for both Nullable and Not Nullable

I've written the following Extension Method Public Function ToUtcIso8601(ByVal dt As Date) As String Return String.Format("{0:s}Z", dt) End Function But I also need a Nullable version of the same method... how…
Chase Florell
  • 46,378
  • 57
  • 186
  • 376
1
vote
3 answers

Kotlin check for null twice in if else

I have an item with variable datePurchased, which can be null. Based on purchase date, I generate a label. When I check if datePurchased is null, in else branch I still have to check for null. It says that smart cast is impossible, because it's a…
Marius Kaunietis
  • 674
  • 4
  • 17
1
vote
2 answers

Nullable Bit field true or false detection

If I have a nullable bit field (named 'Disabled') and the data is as follows: ID | Name | Disabled -------------------- 1 | Mine | null 2 | Yours| 1 If I then execute the following Linq To Entities statement no values are returned: from r in…
Paul Zahra
  • 9,522
  • 8
  • 54
  • 76
1
vote
0 answers

Do nullable value types have special null checking logic?

Nullable is a ValueType so you are guaranteed to never have a null reference on a Nullable, but the following passes; [Test] public void ShouldTestNullRef() { int? value = null; IsNull(value).Should().BeTrue(); //…
leat
  • 1,418
  • 1
  • 15
  • 21
1
vote
6 answers

C# Handling Null Values

I have CustomerID declared as int? CustomerID=null; I am checking null values while reading DataReader Id = reader["CustomerId"] is DBNull ? null :Convert.ToInt32(reader["CustomerID"]); It is throwing Type of conditional expression cannot be…
Amit
  • 447
  • 1
  • 6
  • 8
1
vote
1 answer

Exactly how to use nonnull in certain cases in Objective C

I have read many posts about nullability but I can't for the life of me make my warnings go away. Here are a couple of examples: playPause = @[[UIImage imageNamed:@"Play"], [UIImage imageNamed: @"Pause"]]; [imagePropertiesFileHandle…
1
vote
2 answers

how can I return the index of an object in a 2 dimensional array?

I am working with a 2-D array of nullable booleans bool?[,]. I am trying to write a method that will cycle through its elements 1 at a time starting at the top, and for each index that is null, it will return the index. Here is what I have so…
Cody
  • 53
  • 1
  • 5
1 2 3
99
100