How to initialize a list of strings List string with many string values

0 votes

How may a list of strings be initialised (using a C# initializer)? I tried using the example below, but it didn't work.

List<string> optionList = new List<string>
{
    "AdditionalCardPersonAddressType","AutomaticRaiseCreditLimit","CardDeliveryTimeWeekDay"
}();
Jun 11 in C# by pranav
• 2,320 points
10 views

1 answer to this question.

0 votes

Simply remove the () at the end.

List<string> optionList = new List<string>
            { "AdditionalCardPersonAdressType", /* rest of elements */ };
answered Jun 13 by krishna
• 1,340 points

Related Questions In C#

0 votes
1 answer

How to find the extension of a file in C#

Go to here https://docs.microsoft.com/en-us/dotnet/api/system.io.path.getextension?redirectedfrom=MSDN&view=net-6.0#System_IO_Path_GetExtension_System_String_ string myFilePath = @"C:\MyFile.txt"; string ext ...READ MORE

answered Jun 21 in C# by jyoti
• 1,240 points
16 views
0 votes
1 answer

array of string with unknown size

Is there a specific reason why an ...READ MORE

answered Jun 7 in C# by pranav
• 2,320 points
19 views
0 votes
1 answer

How to iterate over a dictionary?

I have seen this being used. In ...READ MORE

answered Jun 7 in C# by pranav
• 2,320 points
14 views
0 votes
1 answer

How do I specify the exit code of a console application in .NET

Simply put, you can return the exit ...READ MORE

answered Jun 11 in C# by pranav
• 2,320 points
20 views
0 votes
1 answer

Python join: why is it string.join(list) instead of list.join(string)?

This is because join is a "string" ...READ MORE

answered Jul 30, 2018 in Python by Priyaj
• 58,080 points
358 views
0 votes
1 answer

What exactly does the .join() method do?

Look carefully at your output: 5wlfgALGbXOahekxSs9wlfgALGbXOahekxSs5 ^                 ^                 ^ I've ...READ MORE

answered Oct 10, 2018 in Python by SDeb
• 13,300 points
176 views
0 votes
1 answer

Validating String against USPS state abbreviations

This is how I'd do it: private static ...READ MORE

answered Nov 10, 2018 in Others by DataKing99
• 8,240 points
1,203 views
0 votes
1 answer

Why is it string.join(list) instead of list.join(string)?

It's because any iterable can be joined ...READ MORE

answered Dec 2, 2020 in Python by Gitika
• 65,850 points
122 views
0 votes
1 answer

How do I turn a C# object into a JSON string in .NET

Newtonsoft.json can be used to accomplish this. ...READ MORE

answered Jun 13 in C# by krishna
• 1,340 points
9 views
0 votes
1 answer

How to practice a language like C#

I believe you should begin with personal ...READ MORE

answered Jun 13 in C# by krishna
• 1,340 points
10 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP