Thread overview
primitive type variables not nullable ?
Feb 08, 2015
Venkat Akkineni
Feb 08, 2015
Venkat Akkineni
Feb 08, 2015
Tobias Pankrath
Feb 09, 2015
bearophile
Feb 11, 2015
Venkat Akkineni
February 08, 2015
	colors = [
		"black" : "నలుపు",
		"white"	: "తెలుపు",
		"red"	: "యెరుపు",
		"green"	: "పచ్చ",
		"blue"	: "నీలం"
	];
	
	writefln("Before: ");
	writeln(colors);
	colors = null;
	writefln("after: ");
	writeln(colors);

This above bit of code is trying to delete all elements at once by assigning a null to colors associative array. Interesting thing is the write output after assigning null to colors variable shows "[]".


Here is the output.

Before:
["blue":"నీలం", "red":"యెరుపు", "white":"తెలుపు", "green":"పచ్చ", "black":"నలుపు"]
after:
[]


So primitive types can never be null ? An null assignment would set the primitive type variable to a default value ?

February 08, 2015
Never mind, stupid question I realize, would delete it if I could.

http://stackoverflow.com/questions/11047276/null-for-primitive-data-types
February 08, 2015
On Sunday, 8 February 2015 at 23:13:33 UTC, Venkat Akkineni wrote:
> Never mind, stupid question I realize, would delete it if I could.
>
> http://stackoverflow.com/questions/11047276/null-for-primitive-data-types

Check for null with (x is null) not via printing to stdout.
February 09, 2015
Tobias Pankrath:

> Check for null with (x is null) not via printing to stdout.

In most cases instead of checking dynamic arrays for null, it's better to use std.array.empty.

Bye,
bearophile
February 11, 2015
Thanks Gentlemen. That helped.

On Monday, 9 February 2015 at 00:00:00 UTC, bearophile wrote:
> Tobias Pankrath:
>
>> Check for null with (x is null) not via printing to stdout.
>
> In most cases instead of checking dynamic arrays for null, it's better to use std.array.empty.
>
> Bye,
> bearophile