Questions tagged [null]

Null means *nothing* or *unknown*, depending on context. Please use the "sql-null" tag for SQL specific questions.

"Null" has different meanings depending on context.

Set theory

Null is another name for the empty set, denoted by the symbol ∅. For this reason, some programming languages use null or nil for the empty list or empty tuple. Lisp uses nil to mean the empty list and the boolean value false.

Pointers and References

Null (or sometimes nil or None), in programming languages that support it, is the value of an uninitialized variable, a pointer that doesn't point to a meaningful memory address, or an object that fails to respond to any message.

Nullable references were invented by C.A.R. Hoare in 1965 as part of the Algol W language. Hoare later described his invention as a "billion-dollar mistake".

For more information, see Null pointer.

Agreeing with Hoare's sentiment, many languages don't have a special null value, choosing to use optional types instead.

Relational Databases

NULL as a special marker in SQL or a relational database stands in place of a value that is missing, or in a join means "no corresponding row." The operators IS NULL and IS NOT NULL are required for comparisons to a literal null: other comparisons between NULL and any value evaluate to "unknown."

For more information, see Null (SQL).

ASCII

Null or NUL is the name given to the character with ASCII code zero (0) - i.e. hex 00. In some languages, notably C, NUL is used to mark the end of a character string.

For more information, see Null character.

16208 questions
89
votes
11 answers

C# okay with comparing value types to null

I ran into this today and have no idea why the C# compiler isn't throwing an error. Int32 x = 1; if (x == null) { Console.WriteLine("What the?"); } I'm confused as to how x could ever possibly be null. Especially since this assignment…
Joshua Belden
  • 10,273
  • 8
  • 40
  • 56
89
votes
6 answers

How to set null value to int in c#?

int value=0; if (value == 0) { value = null; } How can I set value to null above? Any help will be appreciated.
user2902180
  • 1,021
  • 3
  • 12
  • 12
89
votes
1 answer

C# HasValue vs !=null

My question might sound a little foolish but it bugs me every time i face it. What is the difference between : where value.HasValue and where value != null Does HasValue checks if value is null?
oimitro
  • 1,466
  • 4
  • 14
  • 22
89
votes
2 answers

C# code won't compile. No implicit conversion between null and int

Possible Duplicate: Nullable types and the ternary operator: why is `? 10 : null` forbidden? Why doesn't this work? Seems like valid code. string cert = ddCovCert.SelectedValue; int? x = (string.IsNullOrEmpty(cert)) ? null: int.Parse(cert); …
Hcabnettek
  • 12,678
  • 38
  • 124
  • 190
88
votes
5 answers

string.Empty vs null.Which one do you use?

Recently a colleague at work told me not to use string.Empty when setting a string variable but use null as it pollutes the stack? He says don't do string myString=string.Empty; but do string mystring=null; Does it really matter? I know string is…
user712923
  • 1,515
  • 2
  • 16
  • 19
88
votes
8 answers

Why can't I check if a 'DateTime' is 'Nothing'?

In VB.NET, is there a way to set a DateTime variable to "not set"? And why is it possible to set a DateTime to Nothing, but not possible to check if it is Nothing? For example: Dim d As DateTime = Nothing Dim boolNotSet As Boolean = d Is Nothing…
Muleskinner
  • 14,150
  • 19
  • 58
  • 79
88
votes
15 answers

Does assigning objects to null in Java impact garbage collection?

Does assigning an unused object reference to null in Java improve the garbage collection process in any measurable way? My experience with Java (and C#) has taught me that is often counter intuitive to try and outsmart the virtual machine or JIT…
James McMahon
  • 48,506
  • 64
  • 207
  • 283
88
votes
4 answers

NULL in MySQL (Performance & Storage)

What exactly does null do performance and storage (space) wise in MySQL? For example: TINYINT: 1 Byte TINYINT w/NULL 1 byte + somehow stores NULL?
Steve
  • 5,823
  • 7
  • 31
  • 33
87
votes
3 answers

Pandas - check if ALL values are NaN in Series

I have a data series which looks like this: print mys id_L1 2 NaN 3 NaN 4 NaN 5 NaN 6 NaN 7 NaN 8 NaN I would like to check is all the values are NaN. My attempt: pd.isnull(mys).all() Output: True Is…
Boosted_d16
  • 13,340
  • 35
  • 98
  • 158
86
votes
6 answers

Replace null with 0 in MySQL

I am getting NULL values in the results of an operation in MySQL. Is there a way to convert the NULL values into the value 0?
NullVoxPopuli
  • 61,906
  • 73
  • 206
  • 352
85
votes
2 answers

How to specify null value as filter in a Doctrine query?

I am using Doctrine 1.1 in Zend. I am trying to write a query that will return records that have a null value in a certain column. $q = Doctrine_Query::create() ->select('a.*') ->from('RuleSet a') ->where('a.vertical_id = ?',…
Mr B
  • 3,980
  • 9
  • 48
  • 74
85
votes
8 answers

How to check multiple objects for nullity?

Often, I can see a code constructs like following: if(a == null || b == null || c == null){ //... } I wonder if there is any widely used library (Google, Apache, etc.) to check against nullity for multiple objects at once, e.g.: if(anyIsNull(a,…
Krzysztof Wolny
  • 10,576
  • 4
  • 34
  • 46
85
votes
22 answers

Best ruby idiom for "nil or zero"

I am looking for a concise way to check a value to see if it is nil or zero. Currently I am doing something like: if (!val || val == 0) # Is nil or zero end But this seems very clumsy.
csexton
  • 24,061
  • 15
  • 54
  • 57
84
votes
9 answers

How to add nil value to Swift Dictionary?

I have made a request to my server in my app. And posted data something like this.Server side is waiting for all parameters even they are nil. But i couldn't add nil values to dictionary. var postDict = Dictionary
yatanadam
  • 1,254
  • 1
  • 11
  • 19
83
votes
7 answers

Java map.get(key) - automatically do put(key) and return if key doesn't exist?

I am sick of the following pattern: value = map.get(key); if (value == null) { value = new Object(); map.put(key, value); } This example only scratches the surface of the extra code to be written when you have nested maps to represent a…
Sridhar Sarnobat
  • 25,183
  • 12
  • 93
  • 106