第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

C#中的乘積方法

C#中的乘積方法

瀟湘沐 2021-03-11 10:11:42
我正在使用python,并且正在將代碼實(shí)現(xiàn)為c#,并且在python中有方法“ product”,有人知道c#中是否存在類似的東西?如果不是,也許有人可以讓我了解如何自己編寫此功能?產(chǎn)品示例:a=[[[(1, 2), (3, 4)], [(5, 6), (7, 8)], [(9, 10), (11, 12)]], [[(13, 14), (15, 16)]]]b= product(*a)輸出:([(1, 2), (3, 4)], [(13, 14), (15, 16)])([(5, 6), (7, 8)], [(13, 14), (15, 16)])([(9, 10), (11, 12)], [(13, 14), (15, 16)])
查看完整描述

3 回答

?
慕婉清6462132

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超2個(gè)贊

假設(shè)您的意思是itertools.product(看起來像給定的示例):


public static List< Tuple<T, T> > Product<T>(List<T> a, List<T> b)

    where T : struct

{

    List<Tuple<T, T>> result = new List<Tuple<T, T>>();


    foreach(T t1 in a)

    {

        foreach(T t2 in b)

            result.Add(Tuple.Create<T, T>(t1, t2));

    }


    return result;

}

nbstruct在這里意味著T必須是值類型或結(jié)構(gòu)。class如果您需要拋出Lists之類的對象,但是要注意潛在的引用問題,請將其更改為。


然后作為驅(qū)動程序:


List<int> listA = new List<int>() { 1, 2, 3 };

List<int> listB = new List<int>() { 7, 8, 9 };


List<Tuple<int, int>> product = Product<int>(listA, listB);

foreach (Tuple<int, int> tuple in product)

    Console.WriteLine(tuple.Item1 + ", " + tuple.Item2);

輸出:


1, 7

1, 8

1, 9

2, 7

2, 8

2, 9

3, 7

3, 8

3, 9


查看完整回答
反對 回復(fù) 2021-03-24
?
互換的青春

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超6個(gè)贊

對于超過列表數(shù)量有效的產(chǎn)品功能,您可以在此處使用我的CrossProductFunction.CrossProduct代碼:


List<List<Tuple<int>>> a = new List<List<Tuple<int>>> { /*....*/ }

IEnumerable<List<Tuple<int>>> b = CrossProductFunctions.CrossProduct(a)

當(dāng)前,它不接受repeat參數(shù)itertools.product,但是在功能和設(shè)計(jì)上相似。


查看完整回答
反對 回復(fù) 2021-03-24
?
qq_笑_17

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超7個(gè)贊

  這是用c#編寫函數(shù)的語法:


public void product()

        {

          ..........

          .........

        }


查看完整回答
反對 回復(fù) 2021-03-24
  • 3 回答
  • 0 關(guān)注
  • 394 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號