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

  • Home
  • SEARCH
  • 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 7582111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:21:29+00:00 2026-05-30T18:21:29+00:00

Hi with this code I get: cannot implicity convert type string to int. CalculateSumOfList.ServiceReference1.Service1SoapClient

  • 0

Hi with this code I get: cannot implicity convert type string to int.

        CalculateSumOfList.ServiceReference1.Service1SoapClient client = new CalculateSumOfList.ServiceReference1.Service1SoapClient();
        CalculateSumOfList.ServiceReference1.ArrayOfInt arrayOfInt = new CalculateSumOfList.ServiceReference1.ArrayOfInt();
        arrayOfInt.AddRange(listInt);
        int result = client.CalculateSum(arrayOfInt); //error here!
        label1.Text = Convert.ToString(result);

The webmethod I am calling is here:

namespace CalculateWebServiceSum
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {

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

            return sum.ToString();

        }
    }
}
  • 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-30T18:21:30+00:00Added an answer on May 30, 2026 at 6:21 pm

    The error message is pretty clear. Your method, CalculateSum() returns a string. On the line that the error occurs, you’re attempting to use the string result to set the value of an int:

    int result = client.CalculateSum(arrayOfInt);
    ^ type int   ^ returns string
    

    Option 1

    I suggest changing your CalculateSum() to this:

    public int CalculateSum(List<int> listInt)
    {
        return listInt.Sum();
    }
    

    Note: I’m not sure why you’re passing a List<int> to a web service to be summed. If you have List<int>, simply call List<int>.Sum(), no WS needed.

    Option 2

    Since you’re calling .ToString() on the int after retrieving it, why not just retrieve it as a string?

    string result = client.CalculateSum(arrayOfInt);
    
    public string CalculateSum(List<int> listInt)
    {
        return listInt.Sum().ToString();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get the error Cannot implicitly convert type 'string' to 'System.Web.HtmlString' when I attempt
I wrote this code I have these errors Cannot implicitly convert type x.Program.TreeNode' to
The following code gives me the errors: Cannot implicitly convert type T to string.
The following code produces the issue Cannot implicitly convert type 'System.Collections.Generic.IEnumberable<DataField<string>>' to 'DataFields'. An
I have this code: public static IEnumerable<dcCustomer> searchCustomer(string Companyname) { TestdbDataContext db = new
I am learning C# and keep getting an error Cannot implicitly convert type 'int'
The code below does not compile. The compiler error is Cannot implicitly convert type
I can not get to make this comparison in this simple code error ..
I am using this code to get the background image of a div .
i have this code to get the search resutls from the api: querygoogle.php: <?php

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.