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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:34:45+00:00 2026-05-19T12:34:45+00:00

This is a weird requirement I have. I know even my question is quite

  • 0

This is a weird requirement I have. I know even my question is quite confusing. Here is what I want to know.

I’ve two string variables. I need to do equality comparison of the datatype of the underlying value in the string variables. For ex.

string firstVariable = "123"; // It contains integer value. i.e. I can convert it to integer value
string secondVariable = "string" // It contains string value.

Now I need to compare whether datatype of the underlying values of these two strings are same. How can I do this?

Update: Thanks to all for the clarifications and answers. How about if I know the type of one variable?
For ex:

int firstVariable;
string secondVariable = "123". 

Is this possible to check whether the type of the first variable equals to converted value of the secondVariable. When I declared firstVariable as int it doesn’t mean it is always int type. What I mean here is, I know the type of one variable and other variable is string and I want compare equality of the datatypes of firstvariable and value datatype of the secondVariable.

Is Convert.ChangeType will anyway help in the above scenario?

I know this is silly question, but out of curiosity in the language feature exploring, I wanted to know this.

  • 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-19T12:34:46+00:00Added an answer on May 19, 2026 at 12:34 pm

    Written from my head so there may (will) be errors:

    class StringTypeEqualityComparer : IEqualityComparer<string, string>
    {
        public bool Equals(string x, string y)
        {
            int tempInt;
            if (Int32.TryParse(x, out tempInt) && (Int32.TryParse(y, out tempInt))
                return true;
    
            bool tempBool;
            if (Boolean.TryParse(x, out tempBool) && Boolean.TryParse(y, out tempBool))
                return true;
    
            float tempFloat;
            if (Single.TryParse(x, out tempFloat) && Single.TryParse(y, out tempFloat))
                return true;
    
            // And whatever other types you want to compare...
    
            return false;
    
            // But what if two regular strings should also evaluate to equal?
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Getting this weird LINQ error. title = System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,System.String Here is the code I have:
I have a very weird requirement where I need to deal with months. Here
I have a kind of funny and weird requirement this time. I have my
Now, this requirement may seem weird. But i would like to know how to
I have this weird requirement to access scanner, barcode reader, camera etc. from an
I have been witnessing this weird behavior since last night. Here's the fiddle: http://jsfiddle.net/Gqndm/
I have a weird requirement which I need to use inside my Stored Procedure
I have this weird problem with setting up cookies with PHP. Everything worked fine
I have this weird problem where my Google Maps API script doesn't work, no
Bit of a weird one this. I'm rendering datasets on a map and need

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.