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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:15:41+00:00 2026-05-16T18:15:41+00:00

string s1 = 1234; string s2 = 1234.65; string s3 = null; string s4

  • 0
string s1 = "1234"; 
string s2 = "1234.65"; 
string s3 = null; 
string s4 = "123456789123456789123456789123456789123456789";  

result = Int32.Parse(s1); //-- 1234
result = Int32.Parse(s2); //-- FormatException 
result = Int32.Parse(s3); //-- ArgumentNullException 
result = Int32.Parse(s4); //-- OverflowException 

result = Convert.ToInt32(s1); //-- 1234 
result = Convert.ToInt32(s2); //-- FormatException 
result = Convert.ToInt32(s3); //-- 0 
result = Convert.ToInt32(s4); //-- OverflowException 

success = Int32.TryParse(s1, out result); //-- success => true; result => 1234 
success = Int32.TryParse(s2, out result); //-- success => false; result => 0 
success = Int32.TryParse(s3, out result); //-- success => false; result => 0 
success = Int32.TryParse(s4, out result); //-- success => false; result => 0 

From this link

Why do we need these many conversion functions when the intent of the operation is to just convert a string to int.

I am sorry if my question is stupid.

  • 1 1 Answer
  • 1 View
  • 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-16T18:15:41+00:00Added an answer on May 16, 2026 at 6:15 pm

    They do 3 different things:

    Int32.Parse() expects a string which is an exact representation of an integer. It is extremely limited – it either parses a string or explodes.

    Int32.TryParse() is the same as Parse, but has the extra overhead of performing validation. So in cases where you aren’t sure if the incoming string is parseable, it’s better than Parse and catching an exception (very expensive). But TryParse is wasteful in cases where you can be highly confident a simple Parse will do.

    Convert.ToInt32 is the most complex – it actually determines if the incoming object is convertible, not parseable, to an int. It supports converting between many native (known) types, but also inspects the incoming object to see if the object provides its own logic via IConvertible essentially saying “yes, I can be converted to an integer – here’s how”.

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

Sidebar

Related Questions

Assume we have a string like the following : ,34,23,4,5,634,23,12,5,4,3,1234,23,54,,,,,,,123,43,2,3,4,5,3424,,,,,,,,123,,,1234,,,,,,,45,,,56 How can we convert
response.setContentType(text/html); PrintWriter out = response.getWriter(); Connection conn = null; String url = jdbc:mysql://localhost:3306/; String
I have the next string /1234/somename and I would like to extract the somename
I have this string: comment_1234 I want to extract the 1234 from the string.
I have a C# string RIP-1234-STOP\0\0\0\b\0\0\0???|B?Mp?\0\0\0 returned from a call to a native driver.
string = 'Hello _1234_ world _4567_'; string.match(/(\d*)/gi); //,,,,,,,1234,,,,,,,,,,4567,, If I change regext to have
I have a string of that displays like this.... 1235, 3, 1343, 5, 1234,
I'm having trouble capturing the digits in a string of this format (t|b|bug_|task_|)1234 using
I have a plist that looks like this: <dict> <key>Aaron</key> <dict> <key>number</key> <string>1234</string> <key>country</key>
I am developing a generic wrapper around TryParse, as follows: public delegate bool ParseDelegate<T>(string

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.