Shawn Mclean Shawn Mclean - 1 month ago 19
C# Question

permutation of array items

How do I go about getting a combination of an array of strings of count 2? Ie.

List<string> myString = {"a", "b", "c", "d", "f"};


A permutation would look like this:

ab
ac
ad
af
ba
bc
bd
bf
ca
cb
cd
cf

etc...

I have no idea how to begin this algorithm. If it helps, I'd rather do a loop than a recursion because in my actual implementation, I have to assign a value to the permuted items and compare each one to another and select the highest.

nan nan
Answer

Using Linq:

var result = 
    from a in myString
    from b in myString
    where a != b
    select a + b;
Comments