Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
February 08, 2015 primitive type variables not nullable ? | ||||
---|---|---|---|---|
| ||||
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 Re: primitive type variables not nullable ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Venkat Akkineni | 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 Re: primitive type variables not nullable ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Venkat Akkineni | 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 Re: primitive type variables not nullable ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tobias Pankrath | 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 Re: primitive type variables not nullable ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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
|
Copyright © 1999-2021 by the D Language Foundation