I am new to c# and I need to perform a permutation without repetition for the arrays. For example, Below are the 2 string arrays.
string[] str1 = String[]{"E1","E2","E3"};
string[] str2 = String[]{"E1","E2","E3","E4"};
And I need to generate output for str1 as
{"E1","E2","E3","E1 E2","E1 E3","E2 E3","E1 E2 E3"}
and for str2 as
{"E1","E2","E3","E4","E1 E2","E1 E3","E1 E4","E2 E3","E2 E4",
"E3 E4","E1 E2 E3","E1 E2 E4","E1 E3 E4","E2 E3 E4","E1 E2 E3 E4"}`
Also, I would like to compare the output of str1 & str2. If any of the results are matching(ex.:E2 E3
& E2 E3
) then I need to return "Output is matching" but I am stuck on how to proceed with the below coding in c# and the output is repeating and also array length is static. Please guide me.
String[] str1 = { "E1", "E2", "E3" };
List<string> resultedValue = new List<string>();
for (int i = 0; i < str1.Length; i++)
{
for (int j = 0; j < str1.Length; j++)
{
if (i == j) resultedValue.Add(string.Format("[ {0} ]", str1[i]));
else resultedValue.Add(string.Format("[ {0} {1} ]", str1[i], str1[j]));
}
}
Console.WriteLine(resultedValue.ToArray());