本文介绍了的ArrayList数组的C#排列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ArrayList [] myList中,我试图创建数组中的值的所有排列的列表。

I have an ArrayList[] myList and I am trying to create a list of all the permutations of the values in the arrays.

如:(所有值都是字符串)

EXAMPLE: (all values are strings)

myList[0] = { "1", "5", "3", "9" };
myList[1] = { "2", "3" };
myList[2] = { "93" };

myList中的计数可以变化,以便其长度事先不知道。

The count of myList can be varied so its length is not known beforehand.

我希望能够生成所有排列的列表类似于以下(但有一些额外的格式)。

I would like to be able to generate a list of all the permutations similar to the following (but with some additional formatting).

1 2 93
1 3 93
5 2 93
5 3 93
3 2 93
3 3 93
9 2 93
9 3 93

请问一下,我试图完成这个有意义吗?我似乎无法拿出这样做的一个好方法,(如果有的话)。

Does this make sense of what I am trying to accomplish? I can't seem to come up with a good method for doing this, (if any).

编辑:

我不知道,如果递归将与我的愿望,格式化输出在我自己的方式干涉。对不起,我没有什么之前,我是格式化提。


I am not sure if recursion would interfere with my desire to format the output in my own manner. Sorry I did not mention before what my formatting was.

我要结束了建筑上的所有组合的String []数组下面的格式如下图所示:

I want to end up building a string[] array of all the combinations that follows the format like below:

为1 2 93置换

我想输出是val0 = 1; VAL1 = 2;将val2 = 93;

I want the output to be "val0=1;val1=2;val2=93;"

我将与递归实验了。谢谢DrJokepu

I will experiment with recursion for now. Thank you DrJokepu

推荐答案

我很惊讶没有人张贴的LINQ的解决方案。

I'm surprised nobody posted the LINQ solution.

from val0 in new []{ "1", "5", "3", "9" }
from val1 in new []{ "2", "3" }
from val2 in new []{ "93" }
select String.Format("val0={0};val1={1};val2={2}", val0, val1, val2)

这篇关于的ArrayList数组的C#排列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 20:14