i have list of string 开发者_JAVA技巧like this :
Dim totalPrice As New List(Of Integer)
how can i get sum of column(0) (C# or VB) ? thanks
In C#:
var lst = new List<int>();
lst.Sum();
In C#
do the following to conver the string list into a int list and the sum it.
List<string> list_str = new List<string>();
...
var list_int = list_str.Select( (x)=>int.Parse(x) );
int sum = list_int.Sum();
You wont be able to Sum a string but if it where a list of Integers
List<int> totalPrice = new List<int>();
var SumOftotalPrice = (from s in totalPrice
select s).Sum();
may be this should help
int sum = stringList.ConvertAll(Convert.ToInt32).Sum();
精彩评论