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

Why can't an extension of a Nullable be used on a value of type T?

I have an extension method: public static int DoStuff(this MyEnum? enumValue) { ... } I want to invoke it on a value of MyEnum which is known to be not null: MyEnum enumVal = ... var x = enumVal.DoStuff(); // compiler error! Error: error…
Shaul Behr
  • 36,951
  • 69
  • 249
  • 387
1
vote
0 answers

C# Nullable why is object.HasValue possible if object is null?

why is the line: Assert.IsFalse(myInt.HasValue); possible? I would expect a NullPointerException as myInt is null. [TestMethod] public void Test_NullableInt_ShortDeclaration_WithValueAssignment() { int? myInt = null; …
TheAnonymousModeIT
  • 777
  • 1
  • 6
  • 18
1
vote
1 answer

Realm: How can I set an int to nullable, so that if it gets the value "null" back from the json, it can be ignored

I have the following object: @RealmClass public class TripStop extends RealmObject implements Serializable { @Nullable private int arrival_time; private String address; @PrimaryKey private int id; @Nullable private int departure_time; private…
rosu alin
  • 5,674
  • 11
  • 69
  • 150
1
vote
2 answers

How can I find a Label value in my gridview when it is an integer data type

I have a gridview named gvcmi. And on the DataBound event I want color a column based on its value. The column I want to color is bound to a column in my table in the database. That data type for that column is integer. Here is my snippet: protected…
DebPepDevuan
  • 469
  • 14
  • 30
1
vote
1 answer

ReSharper Warning: Base Class [NotNull] While Derived Class Property [CanBeNull] Conflict

Consider the following C#.Net code: using System.Xml; internal class MyXmlReaderClass : XmlReader { private readonly XmlReader _innerReader; public MyXmlReaderClass(...other_parameters... , XmlReader innerReader) { _innerReader…
NW7US
  • 93
  • 3
  • 10
1
vote
0 answers

Enable @Nonnull annotation checking in ant / jUnit?

Background: I have a project that uses Javax @Nonnull annotations. IntelliJ has a nice feature that enables / disables runtime checking of these types of annotations. However, when jUnit is run via Ant, these annotations checks are not performed. We…
Noah
  • 1,966
  • 1
  • 14
  • 29
1
vote
2 answers

Binding to a nullable data type in WPF

Well, this little quirk of WPF is really getting under my skin. So, I have a DataGrid like this:
1
vote
1 answer

Converting from one nullable type to another nullable type

How can one convert from a nullable instance of class A to nullable instance of class B, while B is subclass of A, I tried this but it crashes: class A { } class B:A { } A? instance_1=something_maybe_null; if (instance_1.GetType() ==…
AVEbrahimi
  • 17,993
  • 23
  • 107
  • 210
1
vote
2 answers

passing a null datetime to reportparameter class?

How can I put a null value on datetime variable type? I tried to make it nullable value, but I need to use it in ReportParameter() method to send it to my report but ReportParameter() constructor cannot take a nullable value and the…
1
vote
1 answer

Default value of nullable integer different in If() function

I am trying to understand why the two code samples behave differently. I always believed the If() function to mimic the If language feature. Or am I looking at a behavior of Nullable(Of Integer) that is causing this? Sample #1: If Not…
motto
  • 1,305
  • 3
  • 16
  • 30
1
vote
1 answer

How to read json file to spark dataframe without those data have null value in some column?

My data is like this: {"id":"1","time":123,"sth":100} {"id":"2","sth":456} {"id":"3","time":789,"sth":300} And I write my schema as: StructType( Array( StructField("id", StringType, false), StructField("time", StringType, false), …
林鼎棋
  • 1,995
  • 2
  • 16
  • 25
1
vote
1 answer

Set default annotation to @NonNull in Android Studio

I want to improve my Android projects with Nullness annotations. I read that with the Checker Framework the @NonNull annotation is rarely written, because it is the default. This leads to much cleaner code since you only need to annotate the…
murf
  • 364
  • 4
  • 17
1
vote
1 answer

How to determine size of a value-type using Mono.Cecil

I'm looking a way to determine size in bytes of a value type (TypeReference) in Mono.Cecil. I need it to optimize Nullable equality compare code generation. If value type size > 4, compare HasValue first, then compare values. If value type size <=…
Lex Lavnikov
  • 1,239
  • 9
  • 18
1
vote
2 answers

Directly accessing struct inner value

Not sure how to word this or search for it as I lack the "real name" for this. Certain structs in C# can be used directly as their containing type, take Nullable<> for instance, a Nullable can directly be treated as an int, for…
beau c
  • 93
  • 1
  • 9
1
vote
1 answer

Is it possible that a C# method parameter of some kind of int can accept null and can update argument

As below code expressed, I want SomeMethod Have a parameter of some kind of int can accept null as parameter if parameter is none null, it will use it's value, then update the value of argument variable in Caller2 void Caller1() { …
Fengtao Ding
  • 706
  • 8
  • 17
1 2 3
99
100