2011-02-15 36 views

回答

3

數字字段列的總和從101 Examples

int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; 

double numSum = numbers.Sum(); 

或..

string[] words = { "cherry", "apple", "blueberry" }; 

double totalChars = words.Sum(w => w.Length); 
0

在你的問題中沒有太多的細節,但類似的東西應該可以工作(如果表應該是數據庫表,並且已經生成了數據上下文):

var sum = myDataContext.MyTable.Sum(v => v.MyColumnToSum); 
0

假設「表」是一個DataTable和「場」數字領域,這是不可能性做到像這樣:

sum = table.AsEnumerable().Sum(row => row.IsNull("field") ? 0.0 : (Double)row["field"]); 

這裏我使用雙作爲數字類型。

0
Dim numbers() As Integer = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0} 

Dim numSum = numbers.Sum() 

這是vb,嘗試轉換爲c#或作爲您的特定語言。