www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - primitive type variables not nullable ?

reply "Venkat Akkineni" <venkatram.akkineni gmail.com> writes:
	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 ?
Feb 08 2015
parent reply "Venkat Akkineni" <venkatram.akkineni gmail.com> writes:
Never mind, stupid question I realize, would delete it if I could.

http://stackoverflow.com/questions/11047276/null-for-primitive-data-types
Feb 08 2015
parent reply "Tobias Pankrath" <tobias pankrath.net> writes:
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.
Feb 08 2015
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
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
Feb 08 2015
parent "Venkat Akkineni" <venkatram.akkineni gmail.com> writes:
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
Feb 10 2015