如何生成多个数组的所有排列/组合? [英] How can I generate all permutations / combinations of multiple arrays?

查看:158
本文介绍了如何生成多个数组的所有排列/组合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标很简单,我试图在数据库中生成产品的所有可能组合的列表.

My goal is simple, I am trying to generate a list of all possible combinations for a product in a database.

因此,例如;产品选项如下

So for example; the product options are as follows

  • 产品选项:颜色/值:红色,绿色,蓝色
  • 产品选项:尺寸/值:Small,Med,Large,XL
  • 产品选项:样式/价值观:男人,女人

我希望能够自动生成所有3的每个组合:

I want to be able to auto generate every single combination of all 3:

Small, Red, Mens
Small, Green, Mens
Small, Blue, Mens
etc

无论将2、3、4或5个数组传递给它,我都需要该函数起作用.

I need the function to work whether I pass 2,3,4 or 5 arrays into it.

我已经做了大量的研究,看到了以下文章,但未能实现我的目标.

I've done quite a bit of research and came across the following articles but have been unable to accomplish my goal.

我发现的文章如下:

  • How to Generate Combinations of Elements of a List<T> in .NET 4.0
  • vb .net permutation of string. permutation or combination?

推荐答案

用法:

Dim s1 As String() = New String() {"small", "med", "large", "XL"}
Dim s2 As String() = New String() {"red", "green", "blue"}
Dim s3 As String() = New String() {"Men", "Women"}

Dim ss As String()() = CartesianProduct(s1, s2, s3)

这篇关于如何生成多个数组的所有排列/组合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆