0

i have list of string like this :

Dim totalPrice As New List(Of Integer)

how can i get sum of column(0) (C# or VB) ? thanks

4

4 回答 4

4

在 C# 中:

var lst = new List<int>();
lst.Sum();
于 2011-01-05T05:49:53.970 回答
3

执行以下操作以C#将字符串列表转换为 int 列表并对其求和。

List<string> list_str = new List<string>();
...
var list_int = list_str.Select( (x)=>int.Parse(x) );
int sum = list_int.Sum();
于 2011-01-05T06:22:35.457 回答
2

您将无法对字符串求和,但如果它在整数列表中

List<int> totalPrice = new List<int>();
var SumOftotalPrice = (from s in totalPrice
                       select s).Sum();
于 2011-01-05T05:46:35.397 回答
2

可能这应该有帮助

int sum = stringList.ConvertAll(Convert.ToInt32).Sum();

于 2011-01-05T06:01:58.157 回答