How to initialize a list of strings (List<string>) with many string values

Bilgin Kılı&#231; picture Bilgin Kılıç · Jun 29, 2010 · Viewed 726.9k times · Source

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>
{
    "AdditionalCardPersonAddressType","AutomaticRaiseCreditLimit","CardDeliveryTimeWeekDay"
}();

Answer

Padel picture Padel · Jun 29, 2010

Just remove () at the end.

List<string> optionList = new List<string>
            { "AdditionalCardPersonAdressType", /* rest of elements */ };