-1

I was wondering about the best way to map one value to many in a dictionary (or some other structure) in C#.

What I wanted to do is something like this:

public GenreToEntity = new Dictionary<string, string[]>()
{
    { "filmes", ["Filme"] },
    { "programas", ["Jornalismo", "Variedade", "Série/seriado"] }
};

But it should be static, so I don't want to add values line by line. Is that possible?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291

1 Answers1

1

I got it! The missing part was what @itsme86 suggested:

public static Dictionary<string, List<string>> EntityToGenre = new Dictionary<string, List<string>>()
{
    { "filmes", new List<string>() {"Filme"} },
    { "novelas", new List<string>() {"Novela"} },
    { "programas", new List<string>() {"Jornalismo", "Variedade", "Série/seriado", "Outros" } }
};