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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:25:50+00:00 2026-05-10T20:25:50+00:00

My scenario should be simple… the type I want to convert FROM is ALWAYS

  • 0

My scenario should be simple… the type I want to convert FROM is ALWAYS ‘string’. What I want to convert to… could be many things – ints, DateTimes, … strings, etc.

This would be easy:

string valueToConvertFrom = '123';  int blah = Convert.ToInt32(valueToConvertFrom); 

However… I don’t know (until runtime) that the value I need to convert to is an ‘Int’ (or whatever). I have tried this:

string valueToConvertFrom = '123';  Type convertToType = typeof(int);  object blah = Convert.ChangeType(valueToConvertFrom, convertToType); 

But that gives me the following error: ‘Object must implement IConvertible.’

I don’t want to have to do a switch statement and call ‘Convert.ToBlah’ based on the type name… any suggestions?

  • 1 1 Answer
  • 3 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. 2026-05-10T20:25:50+00:00Added an answer on May 10, 2026 at 8:25 pm

    the clean way to do it is using the a TypeConverter. you can get an instance of a type converter by calling the TypeDescriptor.GetConverter and then using the instance of the type converter to do the convertion. so something like this:

    string valueToConvertFrom = '123';  Type convertToType = typeof(int);  TypeConverter tc =  TypeDescriptor.GetConverter(convertToType);               object blah =tc.ConvertFromString(valueToConvertFrom); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having some trouble with what should be a very simple scenario. For example purposes,
Can I get a complete simple scenario i.e. tutorial that suggest how this should
This should be a common scenario, but could not find any relevant post yet..
I have a simple scenario with a View, a ViewModel and a custom type
I have pretty simple scenario (MVVM) DataTemplate visuals should change based on data I
I have an issue with something that should be very simple databinding scenario. I
The scenario is that a user should get notification (say via typical JS alert
In WCF , when should a TCP binding be used? I know the scenario
Scenario: old legacy code in rpg have to consume data from a new web
OK, I thought this was a simple git scenario, what am I missing? I

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.