I have a given data (I just make it as a List here).
List<string> list1 = new List<string>();
foreach( var x in Regex.Split( "A B C D E F", " " ) )
list1.Add( x );
Now I want to make a final List like this.
List<string[]> list2 = new List<string[]>();
So, I tried with this code (I have tried with LINQ but, no gain).
int i = 0;
string[] array1 = new string[2];
foreach( var x in list1 )
{
if( i % 2 == 0 )
{
array1[0] = x;
}
else
{
array1[1] = x;
list2.Add( array1 );
array1 = new string[2];
}
i++;
}
I'd like to use LINQ for the same result. Please help.
Thanks.
(EDIT: Result should be A and B, C and D, E and F for each item in List 2)
splitmethod andToListwith:List<string> list1 = "A B C D E F".Split(' ').ToList();