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, 2022 in C# by pranav
• 2,590 points
1,096 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, 2022 by krishna
• 2,820 points

Related Questions In C#

0 votes
0 answers

How to add a gridview to a C# winforms project with a list of objects as the datasource

In Visual Studio 2015 community, I'm creating ...READ MORE

Jun 11, 2022 in C# by krishna
• 2,820 points
806 views
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, 2022 in C# by jyoti
• 1,240 points
322 views
0 votes
0 answers

How can I split a string with a string delimiter

Suppose this is my string My name is ...READ MORE

Jun 11, 2022 in C# by krishna
• 2,820 points
197 views
0 votes
0 answers

How to do a LIKE query with linq

How can I use Linq to conduct ...READ MORE

Jun 11, 2022 in C# by pranav
• 2,590 points
214 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,090 points
628 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
348 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
2,253 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,910 points
487 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, 2022 in C# by krishna
• 2,820 points
341 views
0 votes
1 answer

How to practice a language like C#

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

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