Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7600555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:56:20+00:00 2026-05-30T22:56:20+00:00

Im trying to get the sum of a list from a web service. [WebMethod]

  • 0

Im trying to get the sum of a list from a web service.

[WebMethod]
public string CalculateSum(List<int> listInt)
{
       int[] sum = listInt.ToArray();

        return sum; // error under sum on this line

}

But I get the error cannot convert int to string, this should work?

Client Code:

    public partial class Form1 : Form
    {
        List<int> listInt = new List<int>();

        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {

        }
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            listInt.Add(Convert.ToInt32(textBox1.Text));
            textBox1.Clear();
            listBox1.Items.Clear();
            for (int i = 0; i < listInt.Count; i++)
            {
                listBox1.Items.Add(listInt[i]);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            CalculateSumOfList.ServiceReference1.Service1SoapClient client = new CalculateSumOfList.ServiceReference1.Service1SoapClient();
            CalculateSumOfList.ServiceReference1.ArrayOfInt arrayOfInt = new CalculateSumOfList.ServiceReference1.ArrayOfInt();
            arrayOfInt.AddRange(listInt);
            int result = client.CalculateSum(arrayOfInt); //here
            label1.Text = Convert.ToString(result);


        }



    }
}

I get errors with client.CalculateSum(arrayOfInt);

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:56:21+00:00Added an answer on May 30, 2026 at 10:56 pm

    You can use either

     return sum.ToString();
    

    or

    return "" + sum;
    

    But do consider first: Should a function that sums int values really return a string? It seems to make much more sense as an int function:

    public int CalculateSum(List<int> listInt)
    {
        int sum = listInt.Sum();
        return sum;  // now matches the return-type of the method 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to get parameters from a PUT request using HttpServlet#doPut: public void doPut(HttpServletRequest request,
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
Trying to get this to work, with no luck: [DataMember] public Type ParameterType {
I have to get the sum of a list of doubles. If the sum
First of all here what i'm trying to accomplish: Get the sum of etp_product.price
I'm trying to use the SUM function to count rows from 3 tables, which
I am trying to sum in HTML,but template tag return 0 , View.py def
I'm trying to calculate the sum based off of sets of numbers received from
I am trying to sum a list using fold in the Scala interpreter, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.