rliq
August 19th, 2009, 12:22 AM
I have an array of Int32's. I want to get a total sum of the number N's from that array. Not the number of N's but the sum of the N's. And I want to do it using a LINQ expression.
e.g:
If the array contains: { 3, 9, 3, 8, 6, 3, 2, 2, 3 }
if N = 3 the expression should return 12 (because there are four 3's in the array and 3 x 4 = 12)
if N = 2 the expression should return 4 (because there are two 2's in the array and 2 x 2 = 4)
Sorry about the Maths lesson, but it's best to be clear!
Anyone?
e.g:
If the array contains: { 3, 9, 3, 8, 6, 3, 2, 2, 3 }
if N = 3 the expression should return 12 (because there are four 3's in the array and 3 x 4 = 12)
if N = 2 the expression should return 4 (because there are two 2's in the array and 2 x 2 = 4)
Sorry about the Maths lesson, but it's best to be clear!
Anyone?