我想通過一個數組循環,並獲得每個可能的組合,但我需要它在三個級別後停止。例如:數組的所有組合,停在三個級別C#
String[] arr = ["Service1", "Service2", "Service3", "Service4"];
這是有可能存在超過四陣中,但是從這個例子,我想能夠產生以下組合:到目前爲止
Service1, Service2, Serivce3
Service1, Service2, Serivce4
Service1, Service3, Serivce2
Service1, Service3, Serivce4
Service1, Service4, Serivce2
Service1, Service4, Serivce3
Service2, Service1, Serivce3
Service2, Service1, Serivce4
Service2, Service3, Serivce1
Service2, Service3, Serivce4
Service2, Service4, Serivce3
Service2, Service4, Serivce1
Service3, Service1, Serivce2
Service3, Service1, Serivce4
Service3, Service2, Serivce1
Service3, Service2, Serivce4
Service3, Service4, Serivce2
Service3, Service4, Serivce1
Service4, Service2, Serivce3
Service4, Service2, Serivce1
Service4, Service3, Serivce2
Service4, Service3, Serivce1
Service4, Service1, Serivce2
Service4, Service1, Serivce3
什麼我已經嘗試和研究過這些結果,但我不會非常感謝您提供的任何幫助。
'*不給我這些結果*' - 你的代碼給出了什麼結果?你試過了什麼結果? –
[so]是*不*免費代碼寫入服務。預計你會嘗試**自己編寫代碼**。在[做更多研究]之後(http://meta.stackoverflow.com/questions/261592),如果你有問題,你可以**發佈你已經嘗試過**的清單,說明什麼是不工作的**並提供[**最小,完整和可驗證示例**](http://stackoverflow.com/help/mcve)。我建議閱讀[問]一個好問題和[完美問題](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/)。另外,一定要參加[旅遊]。 – Igor
因爲顯然,訂單很重要('Service3,Service4,Service2'和'Service4,Service2,Serivce3'是不同的結果),那麼你在這裏指的通常是* Permutations *,而不是* Combinations * (組合類似於排列,但順序無關緊要)。你可能有更好的運氣使用谷歌搜索。 –