Cartesian product of string[] with itself without duplicate/clone directly in C#

后端 未结 1 1079
时光说笑
时光说笑 2021-01-20 02:05

Please excuse my lack of better terminology. I have a string[] and I\'d like to get the product of a catesian join with itself for later to put in a dictionary.

1条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-20 02:32

    I'm not sure it has a name, but you can use a Where clause to filter out those matching values.

    string[][] arrayOfArrays =
        array1.SelectMany(left => array1, (left, right) => new string[] { left, right })
              .Where(x => x[0] != x[1])
              .ToArray();
    

    0 讨论(0)
提交回复
热议问题