theklc theklc - 1 month ago 15
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>
{
"AdditionalCardPersonAdressType","AutomaticRaiseCreditLimit","CardDeliveryTimeWeekDay"
}();

Answer
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... :)