permutation of array items

前端 未结 4 2023
隐瞒了意图╮
隐瞒了意图╮ 2021-01-14 05:17

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

List myString = {\"a\", \"b\", \"c\", \"d\", \"f\"};
         


        
4条回答
  •  -上瘾入骨i
    2021-01-14 05:54

    Not using LINQ

    List myString = {"a", "b", "c", "d", "f"};
    List result = new List ();
    for (int i = 0; i < myString.Count; i++)
    {
        for (int j = 0; j < myString.Count; j++)
        {
            if (i == j)
                continue;
            result.Add(myString[i] + myString[j]);
        }
    }
    

提交回复
热议问题