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 8963293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:19:30+00:00 2026-06-15T16:19:30+00:00

I have a problem when summing all of bx3.text to t2.text . first I

  • 0

I have a problem when summing all of bx3.text to t2.text.
first I split bx3.text with space

    private void total()
    {
        string[] ps = bx3.Text.Split(new string[] {" "}, StringSplitOptions.None );
        t2.Text = ps.Select(x => Convert.ToInt32(x)).Sum().ToString();
    }

I did try with t2.text = ps[1] and the number showed was correct.
but when i try to sum it all, I got error

“Input string was not in a correct format” on (x =>
Convert.ToInt32(x))

bx3.text is full of user-input number separated by single space ” “

  • 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-06-15T16:19:31+00:00Added an answer on June 15, 2026 at 4:19 pm

    Try this:

     string output = ps.Select(x =>
                                    { 
                                        int myInt = 0;
                                        int.TryParse(x, out myInt);
                                        return myInt;
                                    })
                                    .Sum().ToString();
    

    Above code will sum all integers in ps array and it will omit all non integer values.

    First scenario: if x is integer (x=1)

      int myInt = 0;
      int.TryParse(x, out myInt); // change value of myInt to 1, because x is integer
      return myInt; // return 1
    

    Second scenario: if x is not integer (x=”aaa”)

      int myInt = 0;
      int.TryParse(x, out myInt); // don't change value of myInt, because x is not integer
      return myInt; // return 0
    

    If x is not integer function TryParse always set value of myInt to zero (msdn doc).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So... I have a problem with counting all ccurrences of preg_match and summing/addition first
I have problem with CSS <buttons> in Google Chrome, it shows space between <buttons>
I'm having a problem with summing floats properly from my SQLite database. I have
Have problem with this code var MAIN_LOCATION = http://www.bosscaffe.com/new/; $(#gallery_page).click(function() { $('#gallery_photos').show(); getPhotos(); return
Possible Duplicate: Integer summing blues, short += short problem I have summarized my problem
I have problem with some JS virus on all of my websites. They're on
I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar
I have problem with my query on C, I’m using the oci8 driver. This
I have problem with repopulating form_upload after validation. Other input fields or selectboxes are
I have problem with show or hide form in Window Form Application. I start

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.