Vis*_*hal 16 c# linq extension-methods
我试图做这样的事情 -
List<short> listofshorts= new List<short>();
int s = listofshorts.Sum();
//this does not work...but same code works for a list of ints..
Run Code Online (Sandbox Code Playgroud)
我收到了这个编译错误 -
'System.Collections.Generic.List'不包含'Sum'的定义,最好的扩展方法重载'System.Linq.Queryable.Sum(System.Linq.IQueryable)'有一些无效的参数
任何人都可以建议我如何使用扩展方法来计算短裤的总和?由于某种原因,扩展方法不支持它...
Giu*_*uto 22
int s = listofshorts.Sum(d => d);
Run Code Online (Sandbox Code Playgroud)
您可以为方法提供lambda:
List<short> listofshorts= new List<short>();
int s = listofshorts.Sum(a => (int)a);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5026 次 |
最近记录: |