Is it possible to input numbers into two different arrays like so,

1 2 3 4 5 6 7 8 9

where the first array would hold {1, 3, 5, 7, 9}
and the second array would hold {2, 4, 6, 8}?

Recommended Answers

All 4 Replies

Sure. But as you split that string up you would need to programattically do the splitting into the arrays.

You can unzip an array like that using the Where extension method (in .NET 3.5).

int[] evenPositioned = numbers.Where((x, i) => i % 2 == 0).ToArray();
int[] oddPositioned = numbers.Where((x, i) => i % 2 == 1).ToArray();

So input them into one array and then do the disentangling.

Interesting, I'm not familiar with the .Where method. Where or what object does that exist in?

In System.Linq.Enumerable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.