C 對多個List進行笛卡爾積

2021-06-28 07:42:14 字數 1080 閱讀 6755

csdn廣告是越來越多了,所有部落格筆記不再更新,新** dotnet筆記

using system;

using system.collections;

using system.collections.generic;

using system.text;

using system.linq;

public class descartes}}

else if (layer == dimvalue.count - 1)}}

}}

2:呼叫方法:

using system;

using system.collections.generic;

using system.linq;

using system.text;

namespace dkr

//建立資料來源 集合l2

listl2 = new list();

for (int i =1; i < 4; i++)

//建立資料來源 集合l3

listl3 = new list();

for (int i = 1; i < 3; i++)

//把需要進行笛卡爾積計算的集合放入到 list>物件中

list> dimvalue = new list>();

dimvalue.add(l1);

dimvalue.add(l2);

dimvalue.add(l3);

//建立結果容器 listresult

listresult = new list();

//傳遞給計算方法中計算

descartes.run(dimvalue, result);

//遍歷查詢結果

foreach (string s in result)

console.read();}}

}

3:執行結果(部分截圖)

多個物件list,不用for迴圈求笛卡爾集

業務需求 現在有好多個維度list 機構 listdeptlist 渠道 listchannellist 產品 listproductlist 口徑 listspeclist等維度。dimension 物件有code,name,type屬性。現在需要求所有維度的笛卡爾集的物件。一般我們會想到巢狀fo...

遞迴方式列印多個陣列的笛卡爾積

先宣告兩個全域性變數 private static int length private static int count 呼叫此方法,引數為可變長陣列 private static void execute string.args 遞迴呼叫列印笛卡爾積 private static void pr...

2個不關聯的表進行連線, 預設使用笛卡爾積

專案中有這樣乙個需求 對每個派出所,按天 每個小時為乙個時間段的案件數.查詢,沒有補0 得到一天24個小時段.select to date 2019 06 16 yyyy mm dd rownum 1 24 hours from dual connect by rownum 24 result 20...