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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:29:29+00:00 2026-05-17T02:29:29+00:00

The Convert class has been in existence since .NET 1.0. The IConvertible interface has

  • 0

The Convert class has been in existence since .NET 1.0. The IConvertible interface has also existed since this time.

The Convert.ChangeType method only works on objects of types that implement IConvertible (in fact, unless I’m mistaken, all of the conversion methods provided by the Convert class are this way). So why is the parameter type object?

In other words, instead of this:

public object ChangeType(object value, Type conversionType);

Why isn’t the signature this?

public object ChangeType(IConvertible value, Type conversionType);

Just seems strange to me.

  • 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-17T02:29:29+00:00Added an answer on May 17, 2026 at 2:29 am

    Looking in reflector you can see the top of ChangeType(object, Type, IFormatProvider), which is what’s called under the covers:

    public static object ChangeType(object value, Type conversionType, IFormatProvider provider)
    {
      //a few null checks...
      IConvertible convertible = value as IConvertible;
      if (convertible == null)
      {
        if (value.GetType() != conversionType)
        {
            throw new InvalidCastException(Environment.GetResourceString("InvalidCast_IConvertible"));
        }
        return value;
      }
    

    So it looks like an object of a type that doesn’t implement IConvertible but already is the destination type will just return the original object.

    Granted it looks like this is the only exception to the value needing to implement IConvertible, but it is an exception, and looks like the reason the parameter is object instead.


    Here’s a quick LinqPad test for this case:

    void Main()
    {
      var t = new Test();
      var u = Convert.ChangeType(t, typeof(Test));
      (u is IConvertible).Dump();   //false, for demonstration only
      u.Dump();                     //dump of a value Test object
    }
    
    public class Test {
      public string Bob;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can remember Convert class in .net which is named not in accordance with
.Net framework contains a great class named Convert that allows conversion between simple types,
This has been driving me mad for the past hour and a half. I
I feel like this one has been asked before, but I'm unable to find
This has been covered a couple of times, without a suitable answer: ObjectDataSource firing
First of all I'm sorry if you feel this question has been raised before,
I am using GDI+ Bitmap class to convert an IStream to HBITMAP. I have
Is there a way to take a class name and convert it to a
I am taking a beginning C++ class, and would like to convert letters between
I've been using Markdown for class notes, and it's great. I even do some

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.