HI.
This is what I want to do:
str2 = "91";
str1 = "19";
var testQuery = from c1 in str1
from c2 in str2
select new {c1, c2};
foreach (var enumerable in testQuery)
{
Console.WriteLine(enumerable.c1 + " | " + enumerable.c2);
}
What I want:
9 | 1
1 | 9
What I really get:
1 | 9
1 | 1
9 | 9
9 | 1
The code is a pure example. It might iterate through arrays or some other collection. It will also do some other things, but they are irrelevant to this problem.
Without linq, I could do something like this:
for (int i = 0; i < str1.Length -1; i++)
{
Console.WriteLine(str1[i] + " | " + str2[i]);
}
But I want a query that can do everything I need instead.
Do I really have to create my own enumerator method that uses yield to create what I want?
EDIT: per request: An example of what I'd like to be able to do:
str1 = "91";
str2 = "19";
char[] digitX = str1.ToString().Reverse().ToArray();
char[] digitY = str2.ToString().Reverse().ToArray();
var q = digitX.Select((c1, i) => new {c1 = c1 - '0', c2 = digitY[i] - '0' });
I'd like to pull the reverse etc. in the actual query. So I keep it all gathered. Extra: Being able to pull this with the sql-like sugarcoated syntax, I'd be thrilled. Instead of a method chain, that is.