我已經看遍了所有,但無法弄清楚這一點。你如何總結一個BigIntegers列表?總結一個BigIntegers列表
Using System.Numerics;
Using System.Linq;
List<BigInteger> bigInts = new List<BigInteger>();
BigInteger sum = bigInts.Sum(); // doesn't work
BigInteger sum = bigInts.Sum<BigInteger>(); // doesn't work
BigInteger sum = bigInts.Sum(x => x); // doesn't work
你必須這樣做嗎?
BigInteger sum = new BigInteger(0);
foreach(BigInteger bigint in bigInts)
sum += bigint;
或者只是'bigInts.Aggregate(BigInteger.Add)':) – leppie 2012-04-21 05:15:22
阿列克謝,這正是我在您提出答案後儘快使用的,我查了一下如何使用Aggregate。 @leppie,你能否添加一些解釋你的魔法是如何運作的? – 2012-04-21 05:21:34
@jb .:它只是一個委託,引用'BigInteger.Add'方法。 – leppie 2012-04-21 05:22:49