<div dir="ltr">Greetings<div><br></div><div style>Is there a way to initialize an associative array to a non-null (but still empty) state? The only way I know is by adding an element and then removing it. Did I miss something obvious? Basically I want to write lines 7-8 in the following code in a cleaner fashion. Any ideas?</div>
<div style><br></div><div style>Regards</div><div style>- Puneet</div><div style><br></div><div style><div><font face="courier new, monospace">class Foo { // 1</font></div><div><font face="courier new, monospace"> string[int] _aa; // 2</font></div>
<div><font face="courier new, monospace"> public string[int] aa() { // 3</font></div><div><font face="courier new, monospace"> return _aa; // 4</font></div><div><font face="courier new, monospace"> } // 5</font></div>
<div><font face="courier new, monospace"> this() { // 6</font></div><div><font face="courier new, monospace"> _aa[0] = ""; // 7</font></div><div><font face="courier new, monospace"> _aa.remove(0); // 8</font></div>
<div><font face="courier new, monospace"> } // 9</font></div><div><font face="courier new, monospace">} // 10</font></div><div><font face="courier new, monospace">void main() { // 11</font></div>
<div><font face="courier new, monospace"> Foo foo = new Foo; // 12</font></div><div><font face="courier new, monospace"> string[int] bb = foo.aa; // 13</font></div><div><font face="courier new, monospace"> assert(bb !is null); // 14</font></div>
<div><font face="courier new, monospace"> bb[0] = "zero"; // 15</font></div><div><font face="courier new, monospace"> assert(bb is foo.aa); // 16</font></div><div><font face="courier new, monospace">} // 17</font></div>
<div><br></div></div></div>