Hello,
The initial task is to find all permutations of the byte array.
byte [] SFP = new byte[8] { 0, 1, 2, 3, 4, 5, 6, 7 };
I've found on some forum the following procedure:
public static IEnumerable<IEnumerable
{if (list.Count() == 1)
return new List<IEnumerable
return list.Select((a, i1) => Permute(
list.Where((b, i2) => i2 != i1)).Select(
b => (
new List
).SelectMany(c => c);
}
I use it in this way: var SFP_vars = Permute(SFP); It works fine - the query find all combinations.
The problem is that I can't use foreach to have access to particular memberes of list.
The foreach loop (see below) provoke the runtime error:
InvalidCastException was unhandled. Unable to cast object of type '
Construction, that give error:
foreach (byte[] SFP_var in SFP_vars)
{
}
How to circumvent the problem.
Thanks in advance.
Pavel.

VulpesPosted Sep 4, 2012, 6:28 AM
PavelPosted Sep 4, 2012, 6:39 AM
PavelPosted Sep 4, 2012, 6:08 AM
VulpesPosted Sep 4, 2012, 6:00 AM
In practice, of course, you might not need the code to restrict iteration to 20 (or whatever) permutations if you're printing to a file or doing some other type of processing which doesn't involve printing to the console.
PavelPosted Sep 4, 2012, 5:51 AM
VulpesPosted Sep 4, 2012, 5:36 AM