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

Nullable bool logical "AND" operator behaves differently with true and false

Using bool? variables, can somebody explain why true & null results in null and false & null results in false? void Main() { bool? a = null; bool? b = true; bool? c = a & b; Console.WriteLine($"{b} & NULL => " + c); b =…
Mong Zhu
  • 23,309
  • 10
  • 44
  • 76
1
vote
1 answer

GetType of nullable int returns same as GetType of int

I have a function that gets an expression as parameter. The type of the expression is Func. But when the expression is evaluated, the nullable int is unpacked. See following Code: using System; using System.Linq.Expressions; public class…
Josef Biehler
  • 952
  • 4
  • 16
1
vote
4 answers

Nullable Array and Why Do We Need Them

I see code like this and I understand it as making an array nullable but I dont understand why do we need it since arrays are ref types, so they are already nullable. So, my question is why do we need this? private readonly decimal?[] _amounts = new…
cd491415
  • 823
  • 2
  • 14
  • 33
1
vote
1 answer

False-positive Sonar issue

Question: why does sonar give me warning ("Change this issue so that it does not always evaluate to "false."). I've been able to prove that if (info == null) evaluates to true when the requestEntity doesn't contain a payload that's found in the db.…
Artanis
  • 561
  • 1
  • 7
  • 26
1
vote
1 answer

How do I prevent an invalid operation on a possible null reference in typescript?

Consider this example where a is possibly null, and is explicitly declared so. Even with strict null checks enabled, typescript does not warn me about a possible error here - let a: string | null = "hello" function b() { a =…
Shubham Kanodia
  • 6,036
  • 3
  • 32
  • 46
1
vote
4 answers

Which version of the C# compiler introduced nullable types?

My C# code is being run in a older version of C# (4.0.30319.34209) than in my own development environment. I am wondering if my usage of nullable types will work on this older version of C#. Does anyone know what version of C# nullable types were…
webworm
  • 10,587
  • 33
  • 120
  • 217
1
vote
4 answers

NullPointerException in a fragment problem

For the last few hours I've been trying to find the answer to my question, and after trying out different things, I was unable to fix my problem. What I want is to use an Edittext and a button that does something with that edittext. Here's my code…
pantank14
  • 175
  • 1
  • 10
1
vote
1 answer

Strictifying nullable fields for validation

I'm trying to get the compiler to help me with validation of payloads received over the network. So what I want to do is take a JSON payload over the wire and make sure the compiler complains if all the fields are not set. I know the way to do this…
David K.
  • 6,153
  • 10
  • 47
  • 78
1
vote
1 answer

Identify if a Type is *either* of int or Nullable

Reflection code. I can check if myTypeObject == typeof(decimal) || myTypeObject == typeof(decimal?) Is there any way to do that without repeating decimal? I'm guessing something along the lines of: myRealTypeObject = myTypeObject.IsNullable() ?…
Brondahl
  • 7,402
  • 5
  • 45
  • 74
1
vote
5 answers

Comparing an instance of a type param to null, even with no class constraint?

The following code compiles: class Testing { public bool Test(TKey key) { return key == null; } } However, TKey can be a value type, and possibly not allow the value "null". I know the results of this program,…
TheSoftwareJedi
  • 34,421
  • 21
  • 109
  • 151
1
vote
1 answer

Entity Framework Nullable Types not included in the CreateXXX Method

I'm using Entity Framework 4.0. I have tables with many nullable types. For a table XYZ the Entity Framework creates an object with an insert method named CreateXYZ, but this method only includes the parameters for non-nullable database fields.…
1
vote
1 answer

How to override a wrong nullability annotation in an Objective-C SDK?

It looks like the GoogleCast SDK for iOS (at least version 3.3.0 we shipped the previous version with; maybe this has been fixed in a more recent version we've upgraded to since, but I'd like to be sure) is sometimes sending nils to a delegate when…
Juri Pakaste
  • 1,402
  • 10
  • 15
1
vote
3 answers

Comparing generic Nullable types

Imagine I have a generic method involving type T. In terms of usage, T will only ever be of type Nullable or Nullable. Because T is Nullable, I can't impose the type constraint where T : IComparable on the method. Given this, what is…
Pancake
  • 739
  • 1
  • 5
  • 20
1
vote
1 answer

Bool and Nullable Bool Usage Concerns in T-SQL/MS SQL

My team has a DB table, which is shared across multiple applications. The table has one primary key INT column and most of the columns are nullable boolean using for flags and configuration. Note that not all columns are being used in all…
frostshoxx
  • 538
  • 1
  • 7
  • 24
1
vote
1 answer

How i can send one parameter in to rest api which can be null or have some value?

How i can send one parameter in to rest api which can be null or have some value? i want send this parameter with json. Data is read from an external file,my problem is that this file has several rows and in some of these rows my parameter's value…
Melika
  • 27
  • 6