Something like that?
var chars = indices.SelectMany(i => words.Where(w => i < w.Length)
.Select(w => w[i])).ToList();
Console.WriteLine(string.Join(",", chars)); // lrod
The logic is as follows:
For each index, I would like to go over all of the possible words, and gather characters.
I must check, first, that the index is within the range of the current word.
From each word, I take the character indexed as the current index.
Using the
SelectMany
method, I get a collection of characters rather than a collection ofIEnumerable<char>
.
You can swap between indices
and words
to get the characters in different order:
var chars = words.SelectMany(w => indices.Where(i => i < w.Length)
.Select(i => w[i])).ToList();
Console.WriteLine(string.Join(",", chars)); // lord