I'd like to use LINQ to group my odd and even numbers in two separate arrays.
int[] randNum = randomNums(20, 1000, 1000);
var oddEvnNums = from num in randNum
group ???
select new { odd = oddNums[], even = evnNums[]}
int oddNum = oddEvnNums.odd[0];
int evenNum = oddEvnNums.even[0];
Just create a lookup with a key of num & 1
(equivalent to num % 2
for positive numbers, but sticking with 1 instead of -1 for negative numbers):
var lookup = randNum.ToLookup(num => num & 1);
var even = grouped[0].ToArray();
var odd = grouped[1].ToArray();
Note that a lookup will return an empty sequence if you ask for a key which doesn't have any entries, so you don't need to worry about whether or not there are odd and even numbers.
Alternatively, instead of grouping, you could just potentially go through the whole sequence twice:
var even = randNum.Where(num => (num & 1) == 0).ToArray();
var odd = randNum.Where(num => (num & 1) == 1).ToArray();
That only works if the sequence is the same both times (rather than being randomly generated each time you iterate, for example) but it may be more efficient than the grouping approach.
See more on this question at Stackoverflow