C# 泛型列表列的总和

C# 泛型列表列的总和,c#,.net,vb.net,generics,generic-list,C#,.net,Vb.net,Generics,Generic List,我有如下字符串列表: Dim totalPrice As New List(Of Integer) 如何获得第0列C或VB的和? 谢谢您将无法对字符串求和,但如果它包含整数列表 List<int> totalPrice = new List<int>(); var SumOftotalPrice = (from s in totalPrice select s).Sum(); 在C中: 也许这会有帮助 整数和= strin

我有如下字符串列表:

Dim totalPrice As New List(Of Integer)
如何获得第0列C或VB的和?
谢谢

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

List<int> totalPrice = new List<int>();
var SumOftotalPrice = (from s in totalPrice
                       select s).Sum();
在C中:


也许这会有帮助

整数和= stringList.ConvertAllConvert.ToInt32.Sum

在C语言中,执行以下操作将字符串列表转换为整数列表,并对其求和

List<string> list_str = new List<string>();
...
var list_int = list_str.Select( (x)=>int.Parse(x) );
int sum = list_int.Sum();

可能是个愚蠢的问题,但为什么要使用字符串列表?我确实编辑了这个问题。你能用更好的词来代替“愚蠢”吗?你的问题很模糊,涉及不同的东西。列表没有列。列表就是一组线性的项目。另外,您打算如何获得字符串总数?字符串是如何格式化的?考虑修改你的问题,也许你可以更详细地解释你的目标。实际上,我不知道你的问题是什么意思。ListOf String没有列。每行只有一项,所以没有列的概念。你可以直接在列表和其他IEnumerables上调用Sum etc函数。我知道,这只是为了完整性
List<string> list_str = new List<string>();
...
var list_int = list_str.Select( (x)=>int.Parse(x) );
int sum = list_int.Sum();