Create a List or Dictionary.
Cym13
cpicard at openmailbox.org
Mon Jun 18 13:23:37 UTC 2018
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.
More information about the Digitalmars-d-learn
mailing list