I am trying to Sum a list of floats with built in Sum()
function but I keep getting this error :
Error CS1061: 'System.Collections.Generic.List' does not contain a definition for 'Sum' and no extension method 'Sum' accepting a first argument of type 'System.Collections.Generic.List' could be found (are you missing a using directive or an assembly reference?) (CS1061)
and I have
using System.Collections;
using System.Collections.Generic;
in the beginning of the file:
code :
List<float> x = new List<float>();
x.add(5.0f);
//..
float f = x.Sum();
You need to add to your using
directives:
using System.Linq;
Besides, your code is syntactically wrong. Here's the working version:
var x = new List<float>();
x.Add(5.0f);
var f = x.Sum();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With