c2 classes

Uknown sireeshkodali1 at gmail.com
Fri Apr 6 15:06:01 UTC 2018


On Friday, 6 April 2018 at 14:43:25 UTC, Ali wrote:
> On Friday, 6 April 2018 at 14:31:49 UTC, Alex wrote:
>> On Friday, 6 April 2018 at 13:41:50 UTC, aerto wrote:
>>> [...]
> A question from me, since I am also still learning D
> what is the difference between those following two declarations
>> UUsers[int] uid; UUsers[] uid;

T[U] declares an Associative Array but T[] declares a Dynamic 
Array. Some examples will help:

---
void main()
{
     char[int] s1;
     char[] s2;
     s1[1] = 'c'; //allowed, it is an Associative array. key 1 
stores value 'c'
     s2[0] = 1; //error: out of bounds of array s2
}
---

You can check out the spec[0] and the tour[1]

[0]: https://dlang.org/spec/hash-map.html
[1]: https://tour.dlang.org/tour/en/basics/associative-arrays


More information about the Digitalmars-d-learn mailing list