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

And the programming language is...

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

Jump to Post

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 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.