Greetings,
my objective is to create a Dictionary<string, string> (or Dictionary<string, List<string>>), adding elements to it from a List<string>. The first string of the list should be the key of the dictionary, the other strings the value.

For example:
List<string> list = new List<string>() { "key1", "value_x1", "value_x2", ... };

Recommended Answers

All 2 Replies

And the programming language is...

I would guess c++ but, not knowing every language I don't want to assume.

commented: Did you read the title of this topic? -3

You can use the new constructor of Dictionary<string,List<string>> to pass in the required elements:

List<string> test = new List<string>() { "key1", "value_x1", "value_x2"}; ;
Dictionary<string, List<string>> test2 = new Dictionary<string, List<string>> 
{
    {test[0], test.Skip(1).ToList() }
};
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.