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
2
votes
1 answer

Type.InvokeMember with nullable parameter

Project I've developed a remoting class which is used to replace a subset of WCF. This has been done because we are targeting a mobile Plattform with Unity3D and need to keep the Memory consumption as small as possible. ( So we don't need to include…
Felix K.
  • 6,201
  • 2
  • 38
  • 71
2
votes
2 answers

How to check whether a method parameter is Nullable<> using reflection if it's also an "out" parameter?

With method signatures like: public interface TestInterface { void SampleMethodOut(out int? nullableInt); void SampleMethod(int? nullableInt); } I'm using typeof(TestInterface).GetMethods()[1].GetParameters()[0].ParameterType to get the…
NickL
  • 1,870
  • 2
  • 15
  • 35
1
vote
3 answers

Best way to alter nullable type, if not null, but return null if null already

this sort of thing comes up all the time, this works but is ugly: DateTime? firstDay = null; if (Day.HasValue) firstDay = Day.Value.AddDays(-14); this won't work: DateTime? firstDay = Day.HasValue ? Day.Value.AddDays(-14) : null; unless: DateTime?…
Jack
  • 4,684
  • 2
  • 29
  • 22
1
vote
1 answer

Find underlying DataType (System Type) in the PropertyType.FullName using RegEx or Other possible way?

I have some library that have some properties nullable i want to access the underlying data type of the property using Reflection. System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] How…
Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75
1
vote
3 answers

Report Server - unable to display correct input parameter via Iif() or Switch()

I have a nullable boolean input parameter with the following expression in my textbox: =iif(Parameters!Sorted.Value="","All",iif(Parameters!Sorted.Value="True","Sorted","Unsorted")) and I am trying to display this based on the value of Sorted input…
Neomoon
  • 181
  • 1
  • 3
  • 12
1
vote
1 answer

Linq MVC 2 TryUpdateModel nullable bool

I have been having an issue with updating a nullable bool value using TryUpdateModel. I have a template created to handle the values as so: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> <% if…
Bman
  • 41
  • 3
1
vote
1 answer

Cannot Save Nullable to Azure Table when its Null

For example, I have a bool? Status in c# when the Status = true/false, it can save to Azure table, no problem But when Stats = null, it cannot save(update) to Azure table, the column still keeps the old value I guess it might because Azure table…
Eric Yin
  • 8,737
  • 19
  • 77
  • 118
1
vote
5 answers

Trying to be as terse as possible with C#

I'm looking for a more terse way of expressing the following test in C# where x is a nullable int English: if x has a value AND y > x then do something C# to make more terse: if(x.HasValue && y > x) Analogously, if I wanted to default a nullable…
Bobbler
  • 633
  • 1
  • 7
  • 21
1
vote
1 answer

How can I use nullable types in the Winforms designer?

I have a control that has a minimum/maximum size contraint on it. This constraint is represented by a struct with two nullable properties (null means no limit). For the life of me I cannot get the WinForms designer to accept it. I've tried a…
1
vote
4 answers

Is there a nullable datepicker that I can bind to?

I am looking for a datepicker like what microsoft provides, but it doesn't support null values, and since this is tied to a nullable field on a database that isn't acceptable. I found this one, but according to the comments at the bottom of the page…
Malfist
  • 31,179
  • 61
  • 182
  • 269
1
vote
3 answers

c# empty optional parameters

For example: void building(int doors, bool multi_story) {...} or void building(int doors = 1, bool multi_story = false) {...} Therefore: new building(4, true); new building(1, false); or new building(doors: 4, multi_story: true); new…
alan2here
  • 3,223
  • 6
  • 37
  • 62
1
vote
2 answers

The '.' operator on null nullable

How is it that you can access null nullable's propery HasValue? I looked to the compiled code, and it's not a syntactic sugar. Why this doesn't throw NullReferenceException: int? x = null; if (x.HasValue) {...}
gdoron
  • 147,333
  • 58
  • 291
  • 367
1
vote
2 answers

XmlConvert and nullable results?

In my project I receive an XmlElement of which I have to parse a few properties back to a class. For mapping these I use the XmlConvert class. But the source being XML there often are empty nodes or nodes that are not readable. Rather then…
Boris Callens
  • 90,659
  • 85
  • 207
  • 305
1
vote
2 answers

.Net - Cast or convert a boxed byte?, short? or int? to int?

If I have an object reference that references a byte?, short? or int?, is there a way to unconditionally cast or convert that object reference to int? without writing separate code for each case? For example: byte? aByte = 42; // .. or aByte =…
Boris B.
  • 4,933
  • 1
  • 28
  • 59
1
vote
1 answer

How can I use Nullable abstract types in F#?

Here is what am I trying to do : and [] Figure() = let mutable name : string = "" let mutable color : ColorType = WHITE abstract member Name : string member F.Color with get() = color and set…
cnd
  • 32,616
  • 62
  • 183
  • 313