Checking if a string is null

Hoenir mrmocool at gmx.de
Tue Jul 24 23:32:52 PDT 2007


Max Samukha schrieb:
> Using '== null' and 'is null' with strings gives odd results (DMD
> 1.019):
> 
> void main()
> {
> 	char[] s;
> 
> 	if (s is null) writefln("s is null");
> 	if (s == null) writefln("s == null");		
> }
> 
> Output:
> s is null
> s == null
> 
> ----
> 
> void main()
> {
> 	char[] s = "";
> 
> 	if (s is null) writefln("s is null");
> 	if (s == null) writefln("s == null");		
> }
> 
> Output:
> s == null
> 
> ----
> 
> Can anybody explain why s == null is true in the second example?
> 
Makes sense to me. is compares the pointer and == the content or 
something like that.


More information about the Digitalmars-d-learn mailing list