Cleared AA == and is have different results. Why?
Brother Bill
brotherbill at mail.com
Wed Sep 10 14:01:29 UTC 2025
Page 119 of Programming in D
It seems odd that == null and is null have different values?
Is this a bug or feature?
If a feature, what is the meanings of == null vs. is null?
source/app.d
```
import std.stdio;
void main()
{
// value[key]
int[string] dayNumbers =
// key : value
[
"Monday": 0, "Tuesday": 1, "Wednesday": 2,
"Thursday": 3, "Friday": 4,
"Saturday": 5, "Sunday": 6
];
dayNumbers.remove("Tuesday");
// writeln(dayNumbers["Tuesday"]); // ← run-time ERROR
dayNumbers.clear;
writeln("dayNumbers == null? ", dayNumbers == null);
// Better, use 'is'
writeln("dayNumbers is null? ", dayNumbers is null);
}
```
Console output:
```
dayNumbers == null? true
dayNumbers is null? false
```
More information about the Digitalmars-d-learn
mailing list