When I call this method it will only return the digits before the decimal place for instance:
1
2
3
= 6
This is fine but when I try:
1.5
2
3.5
= 6
How can I get it to sum the decimal places?
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string CalculateSum(List<int> listDouble)
{
return listDouble.Sum().ToString();
}
}
}
If I use public string CalculateSum(List<double> listDouble) the result is always 0.
No matter what I type in.
This is how I am passing information:
{
CalculateSumOfList.ServiceReference1.Service1SoapClient client = new CalculateSumOfList.ServiceReference1.Service1SoapClient();
CalculateSumOfList.ServiceReference1.ArrayOfInt arrayOfInt = new CalculateSumOfList.ServiceReference1.ArrayOfInt();
arrayOfInt.AddRange(listDouble.Select(d => (int)d).ToList());
string result = client.CalculateSum(arrayOfInt);
label1.Text = Convert.ToString(result);
}
Look at your parameters:
That’s a list of integers, despite the name. If you meant it to be a list of doubles, you should change the type:
You’ll need to uncomment your proper
Sumimplementation, too… returning the result of callingToStringon the return value fromEnumerable.Selectreally isn’t going to do what you want.