Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

string

c#

list

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" }(); 
like image 961
Bilgin Kılıç Avatar asked Jun 29 '10 08:06

Bilgin Kılıç


People also ask

How do you initialize a list in C#?

How to declare and initialize a list in C#? List<string> myList = new List<string>() { "one", "two", "three", };


1 Answers

Just remove () at the end.

List<string> optionList = new List<string>             { "AdditionalCardPersonAdressType", /* rest of elements */ }; 
like image 125
Padel Avatar answered Sep 29 '22 00:09

Padel