When I try to run
InvTotal = g.Sum(d => d.Field<double>("Total")) < 0 ? "W" : "N"
, I get a
Unable to cast object of type 'System.Double' to type 'System.String'
error.
How do I need to change the code for it it compile successfully.
I think you need correct parenthesis.
var InvTotal = (g.Sum(d => d.Field<double>("Total")) < 0) ? "W" : "N"
Without them the compiler will compile 0 ? "W" : "N"
first, and the result of that will be used in the comparison.
Sometimes, the C# compiler needs a little help if it comes to the ? operator.
what is the type of InvTotal? I'm guessing it is currently a Double. Should work if you change the type to String, or remove the declaration of InvTotal and change your line to "var InvTotal = g.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