我试图用内置 Sum()
函数来汇总浮点数列表但我一直收到此错误:
错误CS1061:'System.Collections.Generic.List'不包含'Sum'的定义,并且没有可以找到接受类型'System.Collections.Generic.List'的第一个参数的扩展方法'Sum'(是你吗?缺少using指令或汇编引用?)(CS1061)
我有
using System.Collections;
using System.Collections.Generic;
在文件的开头:
代码:
List<float> x = new List<float>();
x.add(5.0f);
//..
float f = x.Sum();
1 回答
您需要添加到
using
指令:此外,您的代码在语法上是错误的 . 这是工作版本: