theklc theklc - 1 year ago 127
C# Question

How to initialize a C# string list (List<string>) with many string values

How is it possible to initialize (with a C# initializer) a list of strings? I have tried with the example below but it's not working.

List<string> optionList = new List<string>

Answer Source
List<string> mylist = new List<string>{ "element1", "element2", "element3" };

I shall refrain from being worried about some of the details in the OP's list... :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download