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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:09:24+00:00 2026-05-24T05:09:24+00:00

What is the difference (both in terms of correctness and performance) between doing the

  • 0

What is the difference (both in terms of correctness and performance) between doing the following comparisons.

int a = 100;
string b = "100";

if (a == Convert.ToInt16(b))
    //Do something

if (a.ToString() == b)
    //Do Something

If I have a string value that is always an int (say for storing an int in a hidden field on a webpage) I have always compared both values as integers because that is what the data is representing, but I would like a more technical reason.

  • 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-24T05:09:27+00:00Added an answer on May 24, 2026 at 5:09 am

    Comparing strings somewhat works for equality and inequality, but not for other comparisons.

    For instance, a < Convert.ToInt16(b) is not the same thing as a.ToString() < b.

    For that reason alone, I personally always prefer comparing numbers instead of strings.

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

Sidebar

Related Questions

What's the difference between std::string and std::basic_string ? And why are both needed?
What is the difference between sizeof(3.0) and sizeof(3.0f) I was expecting both of them
What is the difference between objectForKey and valueForKey ? I looked both up in
What is the difference between System.Web.Cache and HTTPContext.Curent.Cache? In which cases both are used?
What is the difference between the id and name attributes? They both seem to
What's the difference between window.location and document.location? Should both of them reference the same
What is the difference between Semantic-markup and Semantic Web ? Are both same concepts?
In CSS, what is the difference between cascading and inheritance? Or are both the
What is the difference between Builder Pattern and Flyweight Pattern in terms of usage,
Are there known difference(s) between String.replaceAll() and Matcher.replaceAll() (On a Matcher Object created from

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.