How to re-initialise an associative array.

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Nov 6 09:48:24 PST 2013


On Wed, Nov 06, 2013 at 05:15:34PM +0100, Gary Willoughby wrote:
> A simple request but i'm failing hard. How do i re-init an
> associative array?
[...]

Just assign null to it:

	import std.stdio;
	void main() {
		int[string] aa;
		aa["a"] = 1;
		aa["b"] = 2;
		writeln(aa);

		aa = null;
		aa["a"] = 2;
		aa["b"] = 1;
		writeln(aa);
	}

Output:

	["a":1, "b":2]
	["a":2, "b":1]

The GC will take care of cleaning up the old data.


T

-- 
Don't get stuck in a closet---wear yourself out.


More information about the Digitalmars-d-learn mailing list