Thread overview |
---|
June 18, 2018 Create a List or Dictionary. | ||||
---|---|---|---|---|
| ||||
Hello, I'm having a problem, how can I create a List or Dictionary in D? In C #, I can create a tuple list, example: var musicList = new List <(string URL, string Artist, string Title, string Cover, string Duration)> (); In Google did not find anything, tell me please how to get out of this situation? |
June 18, 2018 Re: Create a List or Dictionary. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sunny | On 18/06/2018 11:44 PM, Sunny wrote: > Hello, I'm having a problem, how can I create a List or Dictionary in D? > > In C #, I can create a tuple list, example: > > var musicList = new List <(string URL, string Artist, string Title, string Cover, string Duration)> (); > > In Google did not find anything, tell me please how to get out of this situation? https://dlang.org/spec/arrays.html#dynamic-arrays https://dlang.org/spec/hash-map.html |
June 18, 2018 Re: Create a List or Dictionary. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sunny | On Monday, 18 June 2018 at 11:44:43 UTC, Sunny wrote:
> Hello, I'm having a problem, how can I create a List or Dictionary in D?
>
> In C #, I can create a tuple list, example:
>
> var musicList = new List <(string URL, string Artist, string Title, string Cover, string Duration)> ();
>
> In Google did not find anything, tell me please how to get out of this situation?
If I read you well it seems the simplest equivalent code would be:
struct MusicItem {
string URL;
string Artist;
string Title;
string Cover;
string Duration;
}
MusicItem[] musicList;
You could technically use tuples to get to the same point but I don't really
see a point, structs fit that purpose very well.
Then you can:
musicList ~= MusicItem(url, artist, title, cover, duration);
musicList = [musicItem1, musicItem2];
or for dictionnaries:
MusicItem[string] musicDictionnary = [
"shortID1": MusicItem(foo, bar, baz, bak, biz, sub),
"shortID2": MusicItem(foo, bar, baz, bak, biz, sub),
];
etc.
|
June 19, 2018 Re: Create a List or Dictionary. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Cym13 | On Monday, 18 June 2018 at 13:23:37 UTC, Cym13 wrote:
Yes, this is what need, thank you very much for your help. :-)
> On Monday, 18 June 2018 at 11:44:43 UTC, Sunny wrote:
>> [...]
>
> If I read you well it seems the simplest equivalent code would be:
>
> struct MusicItem {
> string URL;
> string Artist;
> string Title;
> string Cover;
> string Duration;
> }
>
> MusicItem[] musicList;
>
> You could technically use tuples to get to the same point but I don't really
> see a point, structs fit that purpose very well.
>
> Then you can:
>
> musicList ~= MusicItem(url, artist, title, cover, duration);
> musicList = [musicItem1, musicItem2];
>
> or for dictionnaries:
>
> MusicItem[string] musicDictionnary = [
> "shortID1": MusicItem(foo, bar, baz, bak, biz, sub),
> "shortID2": MusicItem(foo, bar, baz, bak, biz, sub),
> ];
>
> etc.
|
June 19, 2018 Re: Create a List or Dictionary. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sunny | On Tuesday, 19 June 2018 at 05:52:00 UTC, Sunny wrote: > On Monday, 18 June 2018 at 13:23:37 UTC, Cym13 wrote: > > Yes, this is what need, thank you very much for your help. :-) > >> [...] I recommend that you take the D tour if you can, it explains all those fundamental features quite well I think. https://tour.dlang.org/ |
June 19, 2018 Re: Create a List or Dictionary. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Cym13 | On Tuesday, 19 June 2018 at 09:07:46 UTC, Cym13 wrote: > On Tuesday, 19 June 2018 at 05:52:00 UTC, Sunny wrote: >> On Monday, 18 June 2018 at 13:23:37 UTC, Cym13 wrote: >> >> Yes, this is what need, thank you very much for your help. :-) >> >>> [...] > > I recommend that you take the D tour if you can, it explains all those fundamental features quite well I think. https://tour.dlang.org/ I read about D here - https://www.tutorialspoint.com/d_programming/index.htm I've been studying D for about 5 days, I switched from C #, I figured it all out, but with a convenient implementation of the sheets there was a problem. |
June 19, 2018 Re: Create a List or Dictionary. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sunny | On 06/19/2018 11:50 AM, Sunny wrote: > I read about D here - https://www.tutorialspoint.com/d_programming/index.htm I'd advise against using that tutorial. Last time I looked at it, it seemed to be of low quality [1]. And the better parts seemed to be stolen from Ali Çehreli's "Programming in D", which is available for free, too: http://ddili.org/ders/d.en/ [1] https://forum.dlang.org/post/onstqa$255e$1@digitalmars.com |
Copyright © 1999-2021 by the D Language Foundation