Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add strings to List<string[]> list

Tags:

c#

.net

I'm new to C#, I need to do the following:

I need to declare a List

List<string[]> myList = new List<string[]>();

Now the conditions and adding to the list should work as follows (in pseudo code):

for int i = 0 to N
if nNumber == 1 add string[i] to myList[0]
else to myList[1]

In the end, I would have 2 members in my list, each member having several strings.

I am not sure how I can add these strings to the members as the method List(Of T).Add inserts members to the list and I do not want this.

like image 893
Sunscreen Avatar asked Dec 28 '22 10:12

Sunscreen


1 Answers

        var myList = new List<string>[] { new List<string>(), new List<string>() }; 

        for (int i = 0; i <= 12; i++)
        {
            if (i == 1)
                myList.Last().Add(i.ToString());
            else
                myList.First().Add(i.ToString());
        }
like image 164
mjwills Avatar answered Jan 08 '23 04:01

mjwills