That's very inefficent at the moment - all those calls to ElementAt could be going through the whole sequence (as far as they need to) each time. (It depends on the implementation of the sequence.)
However, I'm not at all sure I even understand what this code is doing (using foreach loops would almost certainly make it clearer, as would iterating forwards instead of backwards. Could you give some sample input? and expected outputs?
EDIT: Okay, I think I see what's going on here; you're effectively pivoting valueCollections. I suspect you'll want something like:
static Dictionary<int, string[]> MergeArrays(
IEnumerable<int> idCollection,
params IEnumerable<string>[] valueCollections)
{
var valueCollectionArrays = valueCollections.Select
(x => x.ToArray()).ToArray();
var indexedIds = idCollection.Select((Id, Index) => new { Index, Id });
return indexedIds.ToDictionary(x => Id,
x => valueCollectionArrays.Select(array => array[x.Index]).ToArray());
}
It's pretty ugly though. If you can make idCollection an array to start with, it would frankly be easier.
EDIT: Okay, assuming we can use arrays instead:
static Dictionary<int, string[]> MergeArrays(
int[] idCollection,
params string[][] valueCollections)
{
var ret = new Dictionary<int, string[]>();
for (int i=0; i < idCollection.Length; i++)
{
ret[idCollection[i]] = valueCollections.Select
(array => array[i]).ToArray();
}
return ret;
}
I've corrected (hopefully) a bug in the first version - I was getting confused between which bit of the values was an array and which wasn't. The second version isn't as declarative, but I think it's clearer, personally.