I have a list that is just 1 row initially as such:
One
Two
Three
Four
Five
Six
Seven
I would then have the following in a list - note how I have 2 columns - first column is for odd number, second column is for even number:
One Two
Three Four
Five Six
Seven
I am trying the following:
foreach(var item in mod)
{
int i = 0;
i = i + 1;
if (i % 2 == 0)
{
//add to list here for even number
}
if (i % 2 != 0)
{
// add to list here for odd number
}
}
I'd suggest LINQ:
var odds = mod.Where((item, index) => index % 2 == 0).ToList();
var evens = mod.Where((item, index) => index % 2 == 1).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With