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
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
在 C# 中:
var lst = new List<int>();
lst.Sum();
执行以下操作以C#
将字符串列表转换为 int 列表并对其求和。
List<string> list_str = new List<string>();
...
var list_int = list_str.Select( (x)=>int.Parse(x) );
int sum = list_int.Sum();
您将无法对字符串求和,但如果它在整数列表中
List<int> totalPrice = new List<int>();
var SumOftotalPrice = (from s in totalPrice
select s).Sum();
可能这应该有帮助
int sum = stringList.ConvertAll(Convert.ToInt32).Sum();